TheGoatPRNews
Technology
Editorial

What Is Idempotency? A Practical Guide to Safe Retries

Idempotency means repeating a request has the same effect as sending it once. See which HTTP methods are idempotent, how idempotency keys work, and how to design safe retries.

Illustration of a hand pressing a coral button repeatedly, dotted request lines merging into a single server, and one receipt coming out of the server

You tap Pay. The spinner turns and nothing comes back. Did the payment go through? You can’t tell, so you tap again. Whether that second tap charges you twice depends on one property of the system on the other end: idempotency.

An operation is idempotent when doing it many times has the same effect as doing it once. The IETF draft on the Idempotency-Key header puts it this way: an idempotent operation “can be applied multiple times without changing the result beyond the initial application.”

This guide covers HTTP methods, why retries happen, how to design idempotency keys, and how the same idea protects queue and webhook consumers. Examples are language-agnostic pseudocode. Sources were checked on 9 November 2026.

Idempotency in plain terms

Think about two instructions you could give a bank:

  • “Set the balance of account 42 to 100.” Send it once or five times, and the balance ends up at 100.
  • “Add 100 to account 42.” Send it five times, and the account gains 500.

The first is idempotent. The second is not, and a payment is an “add.” If the first request succeeded but its response was lost, a retry creates a second charge.

The definition is about effect, not the response. MDN’s glossary entry notes that the first DELETE “will likely return a 200,” while later ones return something else. The resource is gone either way, so the operation is still idempotent.

Pay tapped twice: with and without a key

Moment Without an idempotency key With an idempotency key
Tap Pay App sends POST /payments App creates key K once, sends POST /payments with K
Server Charges the card Claims K as in progress, charges the card
Network Response lost; app times out Response lost; app times out
Retry Second POST, which looks like a new payment Same request, same key K
Server Charges again Finds K: 409 if still running, else replays the saved response
Result Two charges One charge

Built from the IETF draft’s timeout case and its 409 for a retry that arrives while the original is still being processed (work in progress), and from MDN’s Idempotency-Key page. Replaying the saved response is how Stripe’s API v1 handles a retry after the first request finished. Claiming the key before charging is our design recommendation. This is an illustration, not a trace of a real system.

Idempotent vs safe HTTP methods

HTTP defines both properties in RFC 9110, the current HTTP Semantics standard.

Safe (section 9.2.1): a method is safe if its semantics are “essentially read-only,” meaning “the client does not request, and does not expect, any state change on the origin server.”

Idempotent (section 9.2.2): a method is idempotent “if the intended effect on the server of multiple identical requests with that method is the same as the effect for a single such request.”

Every safe method is also idempotent. The reverse is not true: PUT and DELETE change state, but repeating them changes nothing further. The table follows RFC 9110’s method registry (Table 7). PATCH comes from RFC 5789, not RFC 9110.

Method Safe Idempotent Defined in
GET yes yes RFC 9110, 9.3.1
HEAD yes yes RFC 9110, 9.3.2
OPTIONS yes yes RFC 9110, 9.3.7
TRACE yes yes RFC 9110, 9.3.8
PUT no yes RFC 9110, 9.3.4
DELETE no yes RFC 9110, 9.3.5
POST no no RFC 9110, 9.3.3
CONNECT no no RFC 9110, 9.3.6
PATCH no no RFC 5789

Three details in the standards are worth knowing:

  1. Idempotency is about what the client asked for. RFC 9110 says the property “only applies to what has been requested by the user; a server is free to log each request separately.” A GET that writes a log line is still an idempotent GET.
  2. The table describes intent, not enforcement. MDN notes: “Nothing is preventing a server in the wild from exposing a non-idempotent endpoint under an idempotent HTTP method.” RFC 9110 says a resource owner “MUST disable or disallow” an unsafe action reached through a safe method.
  3. PATCH can be made idempotent. RFC 5789 says “PATCH is neither safe nor idempotent,” but also that “a PATCH request can be issued in such a way as to be idempotent.” It suggests conditional requests, such as “a strong ETag … in an If-Match header,” so a stale patch fails instead of applying.

Why retries happen

Timeouts and lost responses. The IETF draft describes the core case: a client sends a POST, the request times out, and “the client is left uncertain about the status of the resource.” Stripe’s error-handling guide adds: “Restoring connectivity doesn’t tell you whether the original request succeeded.”

Automatic retries in HTTP clients. RFC 9110 says idempotent requests “can be repeated automatically if a communication failure occurs before the client is able to read the server’s response.” It also notes that “some clients take a riskier approach” and might retry a POST if the connection closed before any response arrived.

Proxies and load balancers. The standard draws a firm line here: “A proxy MUST NOT automatically retry non-idempotent requests.” That rule covers only non-idempotent requests, so nothing in it stops a proxy from retrying an idempotent one. That is one more reason your PUT and DELETE handlers must really be idempotent.

Queues and webhooks. Many messaging systems deliver at least once, which allows duplicates by design. More on this below.

People. Disabling a Pay button helps with double taps, but it can’t stop a retry below the user interface.

RFC 9110 says a client “SHOULD NOT automatically retry a request with a non-idempotent method unless it has some means to know that the request semantics are actually idempotent, regardless of the method, or some means to detect that the original request was never applied.” An idempotency key is that means.

Ways to make an operation idempotent

Before adding keys, check whether the operation can be idempotent by design:

  • Let the client choose the identifier. PUT /orders/{order-id} with a client-generated ID is idempotent by its HTTP definition: the second PUT replaces the order with the same content. A POST /orders that makes up a new ID each time is not.
  • Send absolute values instead of increments. “Set quantity to 3” can be repeated. “Add 1 to quantity” can’t.
  • Use conditional requests. As RFC 5789 suggests for PATCH, an If-Match precondition makes a second, stale attempt fail rather than apply twice.

When none fits, for example a charge or an email, you need an idempotency key.

Idempotency keys: how they work

An idempotency key is a unique value the client generates and attaches to a request. The IETF draft defines it as a value “which the resource uses to recognize subsequent retries of the same request.” If the server sees the same key again, it does not repeat the work. It returns the result of the first attempt.

Is there a standard header?

Not a finished one yet. The Idempotency-Key header is being standardized in draft-ietf-httpapi-idempotency-key-header. On 9 November 2026 the IETF Datatracker listed revision -08 as an “Active Internet-Draft” of the httpapi working group, with working group state “WG Document,” IESG state “I-D Exists,” last updated 22 October 2026 and expiring 25 April 2027. The datatracker’s “Intended RFC status” field reads “(None),” although the -08 document itself says “Intended status: Standards Track.” Like every Internet-Draft, it should be cited only as “work in progress.”

MDN’s Idempotency-Key page marks the header as “Experimental” and “Non-standard.” The draft’s implementation-status section lists organizations that use a custom header with this name, Stripe among them, and others that use different header names or a field in the request body.

The draft’s syntax is simple: the value is a Structured Fields String, and it recommends “a UUID … or a similar random identifier”:

Idempotency-Key: "8e03978e-40d5-43e8-bc93-6894a57f9324"

The client’s job

The client creates one key per logical operation and reuses it for every retry of that operation. MDN states the rule: “A unique key must be used for each new request that is sent, and the same key should be used if that request is resent.”

So the key is created before the first attempt and kept until the outcome is known.

// Client side: one key per user intent, reused across retries
key = new_random_uuid()            // created once, when the user taps Pay
save_locally(order_id, key)        // survives an app restart

repeat up to MAX_ATTEMPTS with backoff:
    response = send POST /payments
                 headers: Idempotency-Key = key
                 body:    { order_id, amount, currency }
    if response received and response.status != 409:
        return response            // 409: first attempt still running, wait and retry
// still no answer: stop and check the payment status before trying again

Stripe, as one company example, gives similar advice. It suggests “V4 UUIDs, or another random string with enough entropy to avoid collisions,” says its keys “are up to 255 characters long,” and warns against using “sensitive data (for example, email addresses or personal identifiers)” as keys.

The server’s job: storage

The server keeps a record for each key it has seen, typically holding:

  • The key itself, scoped to the caller. The draft’s security section recommends “a unique composite key as the idempotent cache lookup key,” for example the client’s key combined with “other client specific attributes known only to the resource.” That stops one client’s key from colliding with, or revealing, another client’s result.
  • A fingerprint of the request. The draft describes an “idempotency fingerprint” generated from the payload, for example a checksum of the whole body or of selected fields.
  • A status, such as in progress or completed.
  • The saved response, so a retry can get the same answer.

Stripe says that for its API v1 it “saves the status code and body of the first request made with a given idempotency key after endpoint execution begins,” and that “retries with the same key return the saved response, including 500 errors.” Stripe doesn’t save a result when parameters fail validation. Whether to replay errors is your design choice.

Expiry (TTL)

Keys need an expiry policy. The draft says a resource “MAY require time based idempotency keys” so it can purge them, and that it “SHOULD define such expiration policy and publish it in the documentation.” MDN repeats that “the key expiry behavior must be defined and documented.”

Stripe’s documented window is one example: for API v1, keys can be removed “after they’re at least 24 hours old,” and if a key “is reused after the original is pruned,” Stripe treats it as a new request. Its error guide tells clients to retry “within the first 24 hours” and, after that, to stop and reconcile the outcome.

Same key, different body

A client bug can reuse a key for a different request, such as a new amount. Replaying the old response would hide the bug. The draft says the key “MUST NOT be reused with another request with a different request payload,” and that the server “SHOULD reply with an HTTP 422 status code” when it happens. MDN lists 422 Unprocessable Content for the same case when fingerprinting is supported.

Stripe takes the same line in its own terms: its idempotency layer “compares incoming parameters to those of the original request and errors if they’re not the same.”

Concurrent duplicates and the race window

The hardest case is two copies arriving at nearly the same time, such as a retry that fires while the first attempt is still running.

A naive handler does this:

// Naive: has a race window
if store.find(key) is empty:      // both requests can pass this check...
    charge_card()                 // ...and both charge the card
    store.save(key, response)

Between the lookup and the save, there is a window in which a second request also sees “no record” and runs the charge again. MDN’s short summary of request processing says the server should “perform the operation and respond, and then store the key,” and it separately lists 409 Conflict for a key that is “currently/still being processed.” Returning that 409 needs a record that exists while the work runs. Our recommendation, which is design advice rather than a rule from MDN or the draft, is to make claiming the key a single atomic step, such as an insert that fails if the key already exists (a unique constraint), and to record “in progress” before doing the work:

// Safer: claim the key atomically before doing the work
fingerprint = hash(request.body)
claimed = store.insert_if_absent(
              key = (caller_id, idem_key),
              value = { status: IN_PROGRESS, fingerprint })

if not claimed:
    record = store.get((caller_id, idem_key))
    if record.fingerprint != fingerprint: return 422   // key reused, different body
    if record.status == IN_PROGRESS:      return 409   // still running, retry later
    return record.saved_response                       // finished: replay it

response = do_the_work(request)
store.update((caller_id, idem_key),
             { status: COMPLETED, saved_response: response })
return response

The 409 matches the draft: if a request “is retried, while the original request is still being processed, the resource SHOULD reply with an HTTP 409 status code.” MDN says clients that get a 409 “will need to wait before retrying.” Stripe’s guide gives the same advice: “wait and retry with that key and the same parameters.”

Sequence diagram with four lanes: client app, proxy or load balancer, payment server, idempotency store. The client sends POST /payments with key K through the proxy. The server claims K atomically and the store marks it IN_PROGRESS, then the charge starts. The client times out and retries with the same key; the server finds K in progress and returns 409 Conflict. The charge finishes once and the server saves the response, marking K COMPLETED. A second retry with key K gets the saved response replayed, with no second charge.
A lost response and two retries with the same key: the first retry gets 409 while the original is still running, the second gets the saved response. The 409 follows the IETF draft (work in progress) and MDN; replaying the saved response is how Stripe’s API v1 behaves. The proxy only forwards, because RFC 9110 says a proxy “MUST NOT automatically retry non-idempotent requests.” Claiming the key before the work is our design recommendation.

One gap remains: a crash after the work but before the record says “completed.” If the work and the key record share a database, write both in one transaction. If the work calls an outside system that accepts idempotency keys, pass one downstream too. And decide how records stuck “in progress” after a crash expire.

If a required key is missing, the draft says the server “SHOULD reply with an HTTP 400 status code,” and MDN lists the same case.

Queues and webhooks: at-least-once vs exactly-once

Message consumers face the same problem.

At-least-once delivery means no message is lost, but some may arrive twice. AWS documents this for Amazon SQS standard queues: they “ensure at-least-once message delivery,” but “more than one copy of a message might be delivered, and messages may occasionally arrive out of order.” Its at-least-once page tells developers to design applications to be idempotent, so they “should not be affected adversely when processing the same message more than once.”

Exactly-once is narrower than it sounds. Google Cloud Pub/Sub’s exactly-once delivery is a feature you enable per subscription, with documented limits:

  • Only pull subscriptions support it. “Push and export subscriptions don’t support exactly-once delivery.”
  • It applies “within a cloud region.” If subscribers are spread across regions, the docs say this “can lead to duplicate message delivery, even when exactly-once delivery is enabled.”
  • Even with it enabled, Google tells subscribers to keep track of processing progress and to use that information “to prevent duplicate work when an acknowledgment fails.”

So the guarantee is about delivery inside the messaging system. Your handler’s side effects, such as a database write, an email, or a charge, still need protection. The practical goal is a consumer whose effects happen once, even when a message arrives twice.

Webhooks work the same way. Stripe’s webhook documentation says endpoints “might occasionally receive the same event more than once” and recommends “logging the event IDs you’ve processed, and then not processing already-logged events.” In live mode, Stripe retries deliveries “for up to three days with an exponential back off.”

GitHub’s webhook best practices describe the X-GitHub-Delivery header, in the context of replay attacks, as a way “to ensure that each delivery is unique per event,” and note that on a redelivery the header “will be the same as in the original delivery.”

A deduplicating consumer looks like this:

// Consumer: process each message's effect once
on message received(msg):
    begin transaction
        inserted = processed_ids.insert_if_absent(msg.id)
        if not inserted:
            commit
            acknowledge(msg)          // duplicate: already handled
            return
        apply_effects(msg)            // the actual work, same transaction
    commit
    acknowledge(msg)

Recording the ID and applying the effect in one transaction closes the same race window as with HTTP keys. If the effects are writes to the same database and the process crashes before commit, neither is saved, and the redelivered message is processed normally. Effects outside that database, such as an email, need their own protection.

Common mistakes

  • Generating the key inside the retry loop. Each retry gets a new key, so the server sees new operations. Create the key once per user intent.
  • Check-then-act without atomicity. A separate lookup and insert, or saving the key only after the work, leaves a race window. Claim the key atomically and mark it “in progress” first.
  • Ignoring the request body. Without a fingerprint, a reused key with a different payload silently returns the wrong result. Compare and return 422.
  • Global keys. Scope keys to the caller, as the draft’s security section recommends, and validate their format before using them in a lookup.
  • Trusting “exactly-once” to cover side effects. Delivery guarantees have documented limits. Make handlers idempotent anyway.
  • State changes behind GET. Clients and intermediaries may retry or prefetch it.

FAQ

What is idempotency in simple terms?

An operation is idempotent if doing it several times has the same effect as doing it once. “Set the balance to 100” is idempotent; “add 100 to the balance” is not.

What does idempotency mean in a REST API, and which HTTP methods are idempotent?

It means a client can repeat a request after a timeout or lost response without causing extra changes. RFC 9110 defines GET, HEAD, OPTIONS, TRACE, PUT, and DELETE as idempotent; POST and CONNECT are not. PATCH (RFC 5789) is neither safe nor idempotent by default. APIs add idempotency keys or conditional requests to make such calls safe to retry.

What is an idempotency key?

It is a unique value, often a random UUID, that the client sends with a request and reuses on every retry. The server stores the result of the first request under that key and returns it for duplicates instead of doing the work again.

Is the Idempotency-Key header a standard?

Not yet. On 9 November 2026 it was an active IETF Internet-Draft, draft-ietf-httpapi-idempotency-key-header-08, in the httpapi working group. MDN marks it as experimental and non-standard, although several APIs use a header with this name.

What is the difference between idempotency and exactly-once?

Exactly-once is a delivery guarantee some messaging systems offer. Google Cloud Pub/Sub’s version, for example, applies only to pull subscriptions within a region. Idempotency is a property of your operation that makes duplicates harmless. With at-least-once systems such as SQS standard queues, idempotent consumers are how you get effects that happen once.

How long should idempotency keys be stored?

No standard sets a number. The IETF draft asks servers to define and publish an expiry policy. Stripe documents that its API v1 keys can be removed after at least 24 hours. Pick a window longer than your clients’ retry period.

TheGoatPRNews editorial content is researched and reviewed before publication. See our Editorial Policy.