Deduplicate API requests so retries do not execute the same operation twice
Request deduplication lets a server recognize when the same logical operation arrives again because of a network retry or repeated submission, preventing duplicate side effects. For a state-changing API, store a client-generated unique idempotency key within a caller and operation scope, and make recording the key atomic with the mutation. Comparing request bodies or caching a key alone is not enough for safe deduplication.
Request deduplication lets a server recognize when the same logical operation arrives again because of a network retry or repeated submission, preventing duplicate side effects. For a state-changing API, store a client-generated unique idempotency key within a caller and operation scope, and make recording the key atomic with the mutation. Comparing request bodies or caching a key alone is not enough for safe deduplication.
Idempotency and deduplication
Idempotency means repeating the same intent has the same final effect as applying it once. Deduplication is an implementation technique in which the server remembers an operation identifier so it does not execute the same logical work again. HTTP method semantics may be sufficient in some cases, but when a POST creates a side effect such as a payment, a client that did not receive the response cannot know whether the server already acted.
A safe design procedure
**Define the operation scope.** Specify the logical operation, such as “this user submits this order.” Two identical request bodies can still represent two intentional orders, so do not merge requests merely because their contents match.
**Have the client create a unique key per logical operation.** Reuse it for retries of that operation and create a new one for new work. A random identifier such as a UUID can provide a sufficiently low collision risk. Do not use sensitive values such as email addresses or personal identifiers as keys.
**Validate key scope and request fingerprint.** Scope stored keys at least by tenant or caller, API operation, and idempotency key. If the same key arrives with different parameters, return an explicit mismatch error instead of silently treating it as new work. If useful, store a normalized fingerprint of meaningful fields rather than the entire body.
**Make key recording and side effects atomic.** Use a uniqueness constraint or transaction so only one concurrent request with the same key acquires execution. Prevent partial states where the key is recorded but the work fails, or the work completes but key storage fails. If one database transaction cannot cover external systems, design a recoverable boundary such as an outbox, state machine, or compensation procedure.
**Handle in-progress and completed duplicates differently.** If the original request is still running, you can wait, return a retryable conflict, or offer a status lookup. If it has completed, return a response semantically equivalent to the original result, or the completion response defined by the API contract. Document which behavior clients should expect.
**Publish retention and expiry.** Keeping keys forever costs storage and may create collision risks; deleting them too soon can let a late retry start a new operation. Set and document expiry based on expected retries, delivery delays, and operation lifetime. State in the API contract that a key may be treated as new after retention expires.
**Protect keys and records.** Validate key format and length, isolate records by caller so users cannot read another caller’s saved result, avoid logging raw keys (or log only a safe fragment), and control access to retained data.
Status of the HTTP Idempotency-Key proposal
As checked on 2026-11-19, the IETF HTTPAPI Idempotency-Key document is an active Internet-Draft 08 updated on 2026-10-22, not an RFC. It proposes rules such as not reusing a key with a different request and publishing expiry policy, plus examples for duplicates and concurrent requests. It does not mean every HTTP API supports this header or behaves alike. Check the provider’s key name, scope, retention, and error responses. For example, Stripe API v1 stores the first response after endpoint execution begins and replays it on retries, while its API v2 behavior is described differently.
How to verify
Send the same key and parameters sequentially and concurrently; confirm that the side effect occurs only once. Also exercise the same key with a different body, storage failure, process restart, lost original response, and a late retry after key expiry. Check that a stored result has the same meaning as the original response and that conflict behavior and retry timing are documented. No live API or database was run or tested for this article.
Sources
[IETF HTTPAPI: The Idempotency-Key HTTP Header Field, draft-08](https://datatracker.ietf.org/doc/html/draft-ietf-httpapi-idempotency-key-header)
[AWS Builders’ Library: Making retries safe with idempotent APIs](https://aws.amazon.com/builders-library/making-retries-safe-with-idempotent-APIs/)
[Stripe API: Idempotent requests](https://docs.stripe.com/api/idempotent_requests)