Bird
0
0

You are building a REST API for processing orders where clients may retry requests. Which design best uses idempotency keys to avoid charging customers multiple times?

hard📝 Application Q8 of 15
Rest API - Advanced Patterns
You are building a REST API for processing orders where clients may retry requests. Which design best uses idempotency keys to avoid charging customers multiple times?
AGenerate a new payment transaction for every request regardless of the idempotency key
BStore the payment result keyed by the idempotency key and return it on retries without reprocessing
CIgnore idempotency keys and rely on client-side retry logic only
DDelete stored idempotency keys immediately after processing to save memory
Step-by-Step Solution
Solution:
  1. Step 1: Understand retry risks

    Retries can cause duplicate charges if requests are processed multiple times.
  2. Step 2: Use idempotency keys

    By storing the payment result with the key, the server can return the same result on retries.
  3. Step 3: Avoid duplicate processing

    This prevents multiple charges for the same order.
  4. Final Answer:

    Store the payment result keyed by the idempotency key and return it on retries without reprocessing -> Option B
  5. Quick Check:

    Persist results by key to prevent duplicate payments [OK]
Quick Trick: Persist results by key to avoid duplicates [OK]
Common Mistakes:
MISTAKES
  • Processing every request as new
  • Relying only on client retries
  • Deleting keys too soon causing duplicates

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes