DVA-C02 Question 16
Single answerYou are developing an API that processes payment transactions using AWS Lambda and Amazon API Gateway. To ensure that clients do not accidentally process the same payment multiple times (e.g., due to retries), you decide to implement idempotency in your system. Which approach should you take to ensure idempotency?
- A
Require clients to send a unique idempotency token with each request and store the token with the result in a database.
- B
Use the transaction amount as the identifier for each request to ensure that duplicate requests are ignored.
- C
Disable retries in the API Gateway configuration to prevent duplicate processing of requests.
- D
Log incoming requests and use request timestamps to detect duplicate requests.
Show answer and explanation
Correct answer: A
Explanation
Idempotency ensures that making multiple identical requests has the same effect as making a single request. A common way to implement idempotency is to require clients to send a unique idempotency token with each request. The server can use this token to track whether a request has already been processed and return the same result if the token is seen again. This approach is both reliable and scalable when implemented correctly.
- A. Correct.
This is the correct approach. By requiring clients to send a unique idempotency token and storing it with the result, you can verify if a request has already been processed and return the same result for duplicate requests.
- B. Incorrect.
Using the transaction amount as the identifier is not reliable because two different transactions could have the same amount. This does not ensure idempotency.
- C. Incorrect.
Disabling retries is not a best practice because retries are a common way to handle transient failures in distributed systems. Instead, idempotency should be implemented to safely handle retries.
- D. Incorrect.
Using request timestamps to detect duplicates is not reliable because requests with the same payload but different timestamps would be treated as unique, potentially leading to duplicate processing.