Skip to main content
Reliabilitychapter 2 of 5 · 3 lessons

Idempotency

Executing the same operation multiple times has the same effect as executing it once.

A customer taps pay. The request reaches your server, the card is charged, and the reply is lost on the way back.

Their phone waits 30 seconds, sees nothing, and does what every sensible client does: it tries again. You charge them a second time.

Nothing here is broken. The network dropped one packet, and neither side can tell the difference between a request that never arrived and an answer that never came back.

Retries are everywhere, from mobile clients to queues redelivering to somebody double-clicking a button, and you cannot switch them off. So the second charge has to become impossible instead. An operation is idempotent when running it twice leaves things exactly as running it once would, which is the property that turns every retry above from a threat into background noise.

Lessons

3 in this chapter
  1. Why Retries Need IdempotencyA timeout doesn't tell you whether the operation happened, so every retry is a gamble.2 min
  2. Idempotency KeysThe client names the operation once, so the server recognizes it the second time.2 min
  3. Designing Idempotent OperationsThe cheapest dedup is an operation that is safe to repeat by construction.3 min