The problem in one picture
Your app sends "charge ₹500" to a payments API. The API charges the card. Then the response gets lost: a mobile network drops, a load balancer times out, a pod restarts. Your app sees an error.
Did the charge happen? Your app can't tell. If it gives up, the order may be paid but never shipped. If it retries, the customer may pay twice. Neither is acceptable when money moves.
Why "make it idempotent" is not enough
An operation is idempotent if doing it twice has the same effect as doing it once. Some operations are naturally like that: "set the price to ₹799" or "delete order 42". Repeating them changes nothing.
"Charge ₹500" is not. Neither is "send an email", "add an item to the cart" or "create an order". Each repeat creates a new thing. For these, the server needs a way to recognise that a request is a repeat. That's what an idempotency key is: a unique ID the client generates once and sends with the original request and every retry.
What Stripe actually does
Stripe described this in Designing robust and predictable APIs with idempotency (Brandur Leach, 2017), and the API docs spell out the rules:
The client sends an
Idempotency-Keyheader, and the docs suggest a V4 UUID. Keys can be up to 255 characters.Stripe saves the status code and body of the first request made with a key, and later requests with the same key get that saved result, "including
500errors".If a retry reuses the key with different parameters, Stripe returns an error instead of guessing.
Keys can be removed once they are at least 24 hours old. After that, the same key counts as a new request.
Keys go on
POSTrequests.GETandDELETEdon't need them because they are already idempotent.
Two details are easy to miss. First, replaying a saved 500 sounds odd, but it's the honest answer: the server can't be sure how far the failed attempt got, so it won't quietly try again under the same key. Second, a request that fails validation is not saved, so the client can fix it and retry with the same key.

The retry half of the story
A key makes retries safe. It doesn't make them polite. The same Stripe post recommends exponential backoff: wait roughly 2^n units after the nth failure. It also recommends adding random jitter so a thousand clients that failed at the same moment don't all retry at the same moment.
Without jitter, a brief outage ends with a synchronised wave of retries that can knock the service over again.
Building it yourself
The server side is smaller than it sounds:
On a request with a key, look it up in a store keyed by (account, key).
If it's new, insert it with status "in progress" in the same transaction that starts the work, so two concurrent retries can't both win.
When the work finishes, save the status code and response body against the key.
If the key exists and is finished, compare the parameters, then replay the saved response or return an error.
If the key exists and is still in progress, return a conflict and let the client back off.
Expire keys after a retention window that is longer than your longest retry policy.
Step 2 is the one that matters. Checking "does this key exist?" and then inserting it in a separate step lets two racing retries both run the charge.
How to choose in an interview
Any time your design has a client retrying a write that creates something or moves money, say:
Which operations are naturally idempotent and which need a key.
Who generates the key (the client, once per logical action, not once per attempt).
Where keys live, how long they're kept, and what happens on a concurrent duplicate.
The retry policy: backoff with jitter, and a cap.
Success criteria: check yourself
For each, decide whether it needs an idempotency key:
PUT /users/42/emailwith a new email address.POST /ordersfrom a checkout button that users double-tap.A worker that consumes "send welcome email" messages from a queue that may deliver a message twice.
You've got it if you said: (1) no, setting a value is already idempotent; (2) yes, the client creates one key per checkout attempt, so a double tap reuses it; (3) yes, use the message ID as the key and record it before or with the send, because "deliver at least once" queues will redeliver.
Interview angle
"We'll retry on failure" is an L4 answer. Adding idempotency keys with the concurrent-duplicate case handled is L5. Adding the retention window, backoff with jitter, and what you'd watch, such as the replay rate and the rate of different-params errors that reveal client bugs, is L6.
Next up
Next Thursday: Replication lag, why users sometimes can't see what they just saved, and how Facebook's TAO keeps it from happening to the person who wrote it.


"Once per logical action, not once per attempt" is exactly where agent tool calls go wrong. If the model regenerates the call on retry, it mints a new key each time. Derive the key in code from the task and step ID, outside the model.