Retrying POST and PATCH Safely with the HTTP Idempotency-Key
Retrying a timed-out POST or PATCH is ambiguous: the server may have completed the work even though the client never received the response. When the API supports Idempotency-Key, create one key per logical operation and reuse it with the same request body for every retry. This reduces duplicate side effects only when the server explicitly implements the contract and its retention policy.
Retrying a timed-out POST or PATCH is ambiguous: the server may have completed the work even though the client never received the response. When the API supports Idempotency-Key, create one key per logical operation and reuse it with the same request body for every retry. This reduces duplicate side effects only when the server explicitly implements the contract and its retention policy.
HTTP method idempotency means repeating a request has the same intended effect on server state as performing it once. RFC 9110 defines PUT, DELETE, and safe methods as idempotent and advises clients not to automatically retry non-idempotent methods without a way to know the operation is safe or was never applied. Idempotency-Key adds a service-level retry contract for operations such as POST/PATCH. The referenced document, draft-ietf-httpapi-idempotency-key-header-08, is an active Internet-Draft published in October 2026, not an RFC.
Define the client retry contract first
Suppose a POST /payments request succeeds but its response is lost. A new key on retry can look like a new payment. Generate one sufficiently random key for each logical payment attempt, then reuse that key and the same request content for that attempt's retransmissions. Draft 08 shows a quoted Structured Field string:
Idempotency-Key: "8e03978e-40d5-43e8-bc93-6894a57f9324"Sending the header alone does not prevent duplicates. Confirm in the API documentation that the endpoint honors it, how long keys remain valid, and what a replay returns. The draft recommends that the resource publish its expiry policy.
How the server handles a key
Scope key storage to the relevant principal or account, operation, and key. A request fingerprint over the full body or selected fields can detect reuse with a different amount or payload. Treat fingerprinting and atomic reservation as implementation choices, not draft mandates.
A separate “check then process” sequence is unsafe under concurrency: two requests can both observe no key and charge twice. Use a unique constraint or atomic claim so one request owns the key. Where feasible, commit the business change and key state in one transaction.
| Request state | Handling | Draft 08 recommendation |
|---|---|---|
| New key | Process and store outcome | Process normally |
| Completed key, same content | Do not repeat the side effect; return a response consistent with the completed operation | Consistent with prior result |
| Same key still processing | Do not start duplicate work; describe the state | 409 Conflict |
| Existing key, different content | Reject; do not treat as a new operation | 422 Unprocessable Content |
| Required key missing | Reject before execution | 400 Bad Request |
These are draft recommendations, not final standard requirements. Document the chosen status and body for each endpoint. The draft recommends 409 for an in-flight duplicate, 422 for a key reused with a different payload, and 400 when a required key is missing.
Design responses and side effects together
Decide whether a replay should return only “already processed” or enough of the original status and body for the client to continue. Define which headers are retained, and scope records to the authenticated principal so a replay cannot expose another user's response.
For local database changes, committing the business record and idempotency record in one transaction can keep them aligned. A payment provider, email service, or message broker is outside that local transaction. If the external service supports its own idempotency key, pass the same logical operation key and follow its scope and retention rules. Otherwise, design a way to query or reconcile the external outcome before retrying an ambiguous call. An idempotency key does not guarantee exactly-once execution across a distributed system.
Make retention part of the contract. Expiring keys too soon can turn a delayed retry into a new operation. The draft recommends defining and publishing expiry. Clients should keep a key through the business retry window and avoid reusing it for a new operation after expiry.
Before rollout
Does the endpoint document support, header syntax, retention, and replay behavior?
Does the client generate a sufficiently random key once per logical operation and reuse it on retries?
Are principal and operation part of the key scope, with key format and length validated?
Do same-key/same-request and same-key/different-body cases produce distinct outcomes?
Can concurrent duplicates cause only one business side effect?
Are completed responses, in-flight behavior, failure recovery, and expiry observable and documented?
Can an ambiguous external timeout cause a duplicate payment or message?
The key does not limit a request to one transmission. It identifies one logical operation so the API can define safe retry outcomes. Verify the server's contract first, then implement key reservation, response replay, payload conflict handling, and retention consistently.
References
[The Idempotency-Key HTTP Header Field (Internet-Draft 08)](https://datatracker.ietf.org/doc/html/draft-ietf-httpapi-idempotency-key-header)
[RFC 9110: HTTP Semantics](https://www.rfc-editor.org/rfc/rfc9110.html)
[RFC 9651: Structured Field Values for HTTP](https://www.rfc-editor.org/rfc/rfc9651.html)
[RFC 9562: Universally Unique IDentifiers (UUIDs)](https://www.rfc-editor.org/rfc/rfc9562.html)