A user taps “Pay” and the screen hangs. Did the payment go through? The app retries, and without protection the customer is charged twice. The same happens when a mobile network drops a response or a background job restarts. Idempotency means an operation has the same result however many times it is repeated.
Idempotency keys
The client generates a unique key for each intended operation and sends it with the request. The server stores the key with the result. If the same key arrives again, the server returns the stored result instead of repeating the work. Many payment providers offer this pattern, and your own APIs should too.
Details that matter
- Store the key and result in the same transaction as the operation
- Reject a repeated key that arrives with a different request body
- Keep keys for a sensible window, such as 24 hours
- Handle two identical requests arriving at the same moment, for example with a unique constraint
Beyond payments
Apply the same thinking to order creation, sign-ups, stock reservations, message consumers and scheduled jobs. Naturally idempotent designs help too: “set status to shipped” is safe to repeat, while “add one to the count” is not.
Our engineers and consultants write about what they see in real projects. Have a question about your own systems?





