Last Minute Notes
  • Github
  • Docs
  • Learn
    @sayanstwt
Lessons
0/37 done
  • CAP & PACELC
  • Consistency Models
  • Time & Ordering
  • Consensus with Raft
  • Locks, Leases & Fencing
  • Isolation Levels & Anomalies
  • 2PC & Sagas
  • Idempotency & Exactly-Once
Learn/System Design/Distributed Systems

Idempotency & Exactly-Once

7 min Intermediate 5 steps

Make retries safe with idempotency keys and dedup.

Charged
$100
Intended
$50
Cause
blind retry
ClientPayment APIDatabasePOST /charge $50charge $50×response lostretry: POST /charge $50charge $50 againthe retry looks like a brand new request
request reply failure
In this lessonStep 1 of 5
  1. The problem
  2. Key flow
  3. In progress
  4. Natural
  5. Recap
Step 1 / 5problem

A lost response, a double charge

The charge succeeded but the response was lost. The client cannot tell, so it retries, and the customer is charged twice.

You cannot get exactly-once delivery over an unreliable network.

Key idea

You get at-least-once delivery plus idempotent handling, which has the same effect as exactly-once.

←→ step·R replay·Space pause

You'll learn

  • Why retries cause duplicate effects
  • The idempotency-key flow
  • What happens when a retry arrives mid-flight
  • Preferring naturally idempotent operations
Read the full notesDistributed Systems, 8