SysDesign study
Offline — showing the cached copy.
Home / Software System Design / 9. Idempotency

9. Idempotency

One-liner. At-least-once delivery is the default; make the effect happen once.

Memorize

  • Idempotency key supplied by the client, stored with the result → replay returns the same response.
  • Upsert instead of insert; conditional writes (if version = n).
  • Dedupe window: store keys with TTL ≥ the retry window.
  • Exactly-once end-to-end does not exist across arbitrary systems — it's at-least-once + idempotent effects.
  • Payment APIs: same key + same body = one charge; same key + different body = 409.
RETRY-SAFE WRITE Client API New key: write +store result Seen key: returnstored result
Retry-safe write

Trap. Retrying a POST that creates a resource without a key — duplicates on every timeout. Do this. Ask what happens if the same message is delivered twice, in the same second.

Check

A payment request times out at the client but succeeded server-side. The client retries. What prevents a double charge?