DVA-C02 Question 13
Single answerYou are developing an application that processes customer orders. Each order creates a new record in an Amazon DynamoDB table and triggers a payment transaction through an API. To ensure that duplicate charges are not made in case of network retries or timeouts, what is the best way to implement idempotency in the payment transaction API?
- A
Include a unique client-generated idempotency token in the API request and ensure the server uses it to detect duplicate requests.
- B
Enable DynamoDB's conditional writes to ensure that duplicate entries cannot be written to the table.
- C
Use the AWS SDK's Retry Logic feature to handle retries automatically.
- D
Use a timestamp in the API request to uniquely identify each transaction.
Show answer and explanation
Correct answer: A
Explanation
Idempotency ensures that duplicate requests do not result in duplicate actions. Using a unique client-generated idempotency token in the API request allows the server to identify and reject duplicate requests effectively, preventing duplicate charges in payment transactions. This approach is widely used in payment systems to maintain consistency and correctness.
- A. Correct.
Correct. Including a client-generated idempotency token ensures that the server can detect duplicate requests and process each unique transaction only once, even during retries.
- B. Incorrect.
Incorrect. While conditional writes in DynamoDB prevent duplicate entries in the table, they do not prevent duplicate charges in the payment transaction API.
- C. Incorrect.
Incorrect. Retry logic in the AWS SDK handles retries but does not guarantee idempotency, as it does not prevent duplicate charges in case of retries.
- D. Incorrect.
Incorrect. A timestamp alone is not a reliable method for ensuring idempotency, as it does not prevent duplicates if two requests happen at the same time with the same value.