Backend · core
Idempotency
Idempotency keys and dedup windows for safe retries of mutations.
Mental model
Networks make retries inevitable, and retrying a POST can charge a card twice. An idempotency key lets the client say 'this is the same operation' — the server stores the first result and replays it for duplicates.
How to study Idempotency
Begin by restating the mental model in your own words, then connect it to a concrete system you have built or operated. Name the mechanism, the constraint it addresses, and the trade-off it introduces. Use Stripe — Designing robust APIs with idempotency to check details, but close the source before writing your explanation. Retrieval is the learning step; rereading is only preparation.
Next, compare Idempotency with Retries & DLQ, Payments. Ask what changes in correctness, latency, resource use, operability, and failure recovery. Complete Implement idempotency keys and preserve the command, input, output, and one failed attempt as evidence. Finish by explaining the idea without jargon to someone who has not studied the track.
Proof of understanding
- Explain the mechanism from first principles and identify the state it reads or changes.
- Give one situation where the concept is the right choice and one where it is not.
- Predict a realistic failure mode before running the drill, then compare the prediction with evidence.
- Connect the result to a roadmap or build artifact instead of treating the concept as isolated trivia.
Where it matters
Stripe payments, any mutating API that clients retry.
Common mistakes
- Assuming GET-only idempotency and leaving POST unsafe
- No expiry on stored idempotency keys
- Race between two concurrent requests with the same key
Learn from primary sources
Practice and explain it back
Implement idempotency keys
Add idempotency-key handling to a mutating endpoint: first request executes and stores the result; duplicates replay the stored result.
Expected evidence: Two identical requests with the same key cause one effect.
Open the interactive drill →Review prompts
- Why are idempotency keys needed for POST endpoints?
Build evidence
Use a roadmap capstone to turn this concept into working evidence.