Skip to the guide

Idempotency keys and safe retries

IntermediateConcept3 pages

When a call times out, the only way forward is to try again, and trying again is dangerous whenever the first attempt might have worked (What the network can't promise). Idempotency keys make "try again" safe for actions that must happen once, like charging a card or placing an order. Interviewers ask about them in almost every design that touches money, and the details separate a memorised answer from a real one: where the key comes from, where it's stored, and what happens when two retries arrive together.

A numbered cheque

A cheque has a number printed on it. If you post the same cheque twice by mistake, the bank pays cheque 1042 once and refuses the second, because it keeps a record of the numbers it has already paid. Compare that with the button that calls a lift: press it five times and one lift comes. No number is needed, because "call the lift" means the same thing however often you ask.