DVA-C02 Question 14
Select 3You are developing a serverless application on AWS that processes orders and stores them in DynamoDB. To ensure that duplicate orders are not processed in the event of retries or failures, you decide to use idempotency. Which of the following approaches will help you achieve idempotency in your application?
- A
Include a unique order ID as the primary key in the DynamoDB table and ensure each order has a unique ID.
- B
Implement a retry mechanism with exponential backoff to handle duplicate request scenarios.
- C
Use an AWS SDK feature like 'clientToken' to pass a unique identifier with each request.
- D
Enable DynamoDB Streams to detect duplicate entries and remove any duplicates.
- E
Store a hash of the order data in DynamoDB and check for existence before processing the order.
Show answer and explanation
Correct answers: A, C, E
Explanation
Idempotency ensures that an operation can be performed multiple times without changing the result beyond the initial application. To achieve idempotency in an AWS application, using unique identifiers for requests (e.g., order IDs or client tokens) and checking for duplicates (e.g., using DynamoDB with a hash of the data) are effective strategies. Retry mechanisms or features like DynamoDB Streams may be helpful in other contexts but do not directly enforce idempotency.
- A. Correct.
Including a unique order ID as the primary key in the DynamoDB table ensures that each order is uniquely identifiable, preventing duplicate entries. This is a key practice for implementing idempotency.
- B. Incorrect.
While a retry mechanism with exponential backoff helps with handling transient failures, it does not inherently address the problem of duplicate requests and does not enforce idempotency.
- C. Correct.
Using a unique identifier like 'clientToken' with each request ensures that the request can be uniquely identified, allowing for retries without processing duplicates.
- D. Incorrect.
Enabling DynamoDB Streams is helpful for event-driven architectures but does not inherently prevent or detect duplicate records in the table.
- E. Correct.
Storing a hash of the order data allows you to compare incoming requests with existing records in the table to determine if it is a duplicate, thereby enforcing idempotency.