Loading articles…
Loading articles…
Loading article…
Loading article…
A client sends a payment request, the server commits it, and the response disappears on a flaky connection. The client cannot tell whether the charge happened. Retrying a normal POST may create a second charge unless the server can recognize the same logical operation.
Have the client create a high-entropy key once for a logical action and reuse it only when retrying that action. The server stores the key with the authenticated account, a hash of the request parameters, the operation status, and the original response. Scope the key by account or tenant so two customers cannot collide.
Back the key with a database unique constraint on the chosen scope and key. On the first request, validate the payload, create an in-progress record, execute the business change, and save the response in a transaction where possible. A concurrent retry then contends on the same unique key instead of running a second business operation.
Retry case | Server behavior |
|---|---|
Same key, same payload, completed | Return the saved result without repeating the effect. |
Same key, different payload | Reject it as a conflict; do not reinterpret the old key. |
Same key, operation in progress | Wait briefly or return a documented retryable response. |
New key | Treat it as a new user action. |
If the protected write and idempotency record live in one database, commit them in the same transaction. If the operation crosses a payment provider or another service, model the state explicitly: persist the intent, call the provider using its idempotency mechanism where available, and reconcile uncertain outcomes instead of assuming a timeout means failure.
HTTP defines some methods, including PUT and DELETE, as idempotent by semantics; POST is not guaranteed to be. An idempotency key is an application contract that makes a specific write endpoint safe to retry. The guarantee comes from the server's persistence and transaction design, not from the header alone.
Chief Technology Officer
Newsletter
New articles from our engineers, straight to your inbox. One email a month, no spam.