Pattern · seen in 6 breakdowns across 5 companies
Idempotency Keys
A unique label the client attaches to a request, so the server tells a retry from a new request and does the work only once, no matter how often the same request is retried.
The mechanism
At its core: when a client retries a request, the server needs to tell whether it is a genuine new request or a repeat of one it already handled. A stable key the client attaches with the request answers that: the first one runs and is saved, and every retry with the same key just replays the saved result.
Retry a charge with no key and you pay twice; retry it with a key and the server charges you once.
Definition
An idempotency key is a unique label the client attaches to a request. The first time the server sees that label, it does the work and saves the result under it. If the same label arrives again - a retry - the server does not redo the work; it just returns the saved result. Same label in, same result out, no matter how many times the request is sent.
This is what makes it safe to retry an operation that must not happen twice, such as:
- charging a customer's card
- placing an order or booking a seat
- creating a new account or record
- moving money from one account to another
- sending a one-off notification or email
When a request fails, the client cannot always tell whether it went through - the network may have dropped the reply, or the server may have crashed after doing the work. So the client retries, and the key guarantees the work is not repeated. It is one piece of safe retrying, alongside deciding which failures are worth retrying and controlling how often clients retry.
The key itself is just an agreement between the client and the server: as long as both use the same key, the outcome is the same, no matter what the network did in between - dropped replies, timeouts, a crash and restart. How the server actually stores results and avoids doing the work twice - for example by committing the operation in safe atomic phases - is a separate problem. The pattern is the agreement on the identifier, not the implementation behind it.
One thing the client owns: it must generate the key, and generate it carefully. The server trusts the key to mean this exact operation. So use a fresh key for each new operation - reuse an old one for something new, and you silently get the old result back.
When it applies
Tradeoffs
The same move, 6 ways
Every row is a production system that bet on this pattern — the note says how, in that system's own terms.
Often used together
Patterns sharing breakdowns with this one — derived from co-occurrence, threshold ≥2 shared.
Problems this pattern answers
The walls where its breakdowns live — each opens the cross-company comparison.