Log inStart free
LESSON 23.11 · 4 STAGES · 3 CONTROLS · 3 CHECKSPRO · PREVIEW

Idempotency keys

Eight payments retry a flaky tool, and an idempotency key stops double charges.


Pro lesson. Stage 1 is free to watch. Pro opens all 4 stages, 3 controls and 3 checks, in this lesson and every other.

Go Pro · $8.25/mo
EXPLAINER · 23.11 · KEY BAYNO KEY · 9 CHARGES · $244 FOR $204
01
Stage 1 of 4 · Duplicate charges
A lost reply makes the agent send payment 2 again. Without a key, the tool charges it twice.
Explain it simply

Each lane is one payment, and time runs to the right. The tool charges payment 2, but its reply is lost. The agent times out and sends the call again. The tool cannot tell it is the same payment, so it charges twice.

Eight lanes, one per payment, with no key. Payment 2 is charged twice. In all, the tool takes 244 dollars for 204 dollars owed.

calls and keyswaits and key expiryfailures and extra chargespaid, charged and saved replies
02505007501000mspayment 1payment 2payment 3payment 4payment 5payment 6payment 7payment 8charged$12$80$7$25$60$18$33$9calls without a keycharges$244payment 2: 2 charges × $40 = $80, for $40 owed02505007501000mspayment 1payment 2payment 3payment 4payment 5payment 6payment 7payment 8charged$12$80$7$25$60$18$33$9calls without a keycharges$244payment 2: 2 charges × $40 = $80, for $40 owed
Toy: 8 payments · a tool that fails 30% of calls · 4 attempts with backoff and jitter
STAGE 1 / 4
MATH · STAGE 1HOVER A SYMBOL OR A SHAPE
cp=#{calls the tool runs for p}\sy{c}{grad}{c_p} = \#\{\text{calls the tool runs for } p\}
c2=2  →  2×$40=$80c_2 = 2 \;\to\; 2 \times \$40 = \$80

Every call the tool runs for a payment adds one charge.

Common mix-ups

MYTHAny unique key on each call stops double charges.

The fix, and 1 more mix-up with the diagram to show them, come with Pro.

Predict, then reveal
3 CHECKS · PRO
Q01With a 200 ms timeout and one key per payment, how many payments are charged more than once?

Make your guess, then test it in the diagram. All 3 checks come with Pro.

PRO LESSON · YOU WATCHED STAGE 1 OF 4
Unlock the full explainer
  • 3 more stages and 3 live controls
  • 2 mix-up cards and 3 predict-then-reveal checks
  • Watch it as a narrated video, in three voices
  • Every Pro lesson and capstone · 656 in total

$99 a year, or $15 a month. Cancel any time.