Bird
0
0

Which approach best ensures safe retries without charging twice if the client resends the same request due to a timeout?

hard📝 Application Q15 of 15
Rest API - Advanced Patterns
You are designing a payment API that uses idempotency keys to avoid duplicate charges. Which approach best ensures safe retries without charging twice if the client resends the same request due to a timeout?
AIgnore the idempotency key and process every request independently
BReject any request with an idempotency key that was seen before
CStore the payment result linked to the idempotency key and return it on repeated requests
DProcess the payment again but log a warning for duplicate keys
Step-by-Step Solution
Solution:
  1. Step 1: Understand safe retry requirements

    Safe retries mean the client can resend the same request without causing duplicate charges.
  2. Step 2: Evaluate options

    Store the payment result linked to the idempotency key and return it on repeated requests stores the payment result linked to the key and returns it on repeats, preventing double charges. Ignore the idempotency key and process every request independently processes every request, risking duplicates. Reject any request with an idempotency key that was seen before rejects repeats, which may cause client errors. Process the payment again but log a warning for duplicate keys processes again, causing duplicates.
  3. Final Answer:

    Store the payment result linked to the idempotency key and return it on repeated requests -> Option C
  4. Quick Check:

    Store and reuse result for idempotency [OK]
Quick Trick: Save and reuse payment result by key to avoid duplicates [OK]
Common Mistakes:
MISTAKES
  • Rejecting repeated keys causing client errors
  • Processing duplicates causing double charges
  • Logging warnings but still charging twice

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes