Development

Idempotency

AI-assisted editorial review:

Idempotency is the property that sending the same request several times has the same intended effect on the server as sending it once. In HTTP, a method is idempotent if the intended effect on the server of multiple identical requests is the same as the effect of a single request; PUT, DELETE and the safe methods such as GET, HEAD and OPTIONS are idempotent, while POST and PATCH are not inherently idempotent.[1][2][3] For operations where a duplicate would be costly, such as a payment sent with POST, APIs ask the client to attach a unique idempotency key to each operation, reusing it for retries so that retries are processed only once.[4] Idempotency does not mean every response is identical.[2]

What does Idempotency mean in simple terms?

Think of a button that gives the same result no matter how many times you press it. When the network drops during a payment, the app often cannot tell whether the request reached the server, so it has to send it again. If the request carries an idempotency key, the server recognizes it as the same request and returns the earlier result instead of charging the customer twice.[6][9]

How can Idempotency be explained with an analogy?

It is like an elevator call button: press it ten times and still only one elevator comes.

Where is Idempotency used?

Case 1

Toss Payments — Idempotency keys on a payment API

Toss Payments accepts an Idempotency-Key header on all of its POST APIs; other methods are idempotent on their own, and a key sent with GET is ignored.[5] The server identifies a repeated request by the combination of the idempotency key, the API key, the API URL and the HTTP method, so the same key can be reused on a different endpoint.[5][6] It recommends a sufficiently random unique value such as a UUID.[5]
Result: Keys are valid for 15 days from the first request and can be up to 300 characters; a longer key returns HTTP 400, and a duplicate sent while the first request is still being processed returns HTTP 409.[5]

Case 2

Stripe — Saving the first response

For its API v1, Stripe saves the status code and body of the first request made with a given key once endpoint execution begins, and returns that saved response to retries with the same key, including 500 errors. If the parameters of a retry differ from the original, the request fails, which prevents accidental misuse. GET and DELETE requests do not need keys because they are idempotent by definition.[4]
Result: Keys can be up to 255 characters, may be pruned once they are at least 24 hours old, and are accepted on all v1 POST requests.[4]

Case 3

Kakao Pay — Handling unknown network results

Kakao Pay's gift-card payment team started from the fact that after a network exception such as a timeout, the caller cannot tell whether the request never arrived, succeeded without a response, or failed. Its payment API returns the same response to a repeated request, using a unique per-transaction key to define what counts as "the same request". Because a compensating cancel request can also time out, endless defensive retries are not an option.[7]
Result: In the design described in May 2022, an unknown result is retried once; if it is still unknown, the transaction is stored as "Unknown" and the user is asked to try again, which triggers recovery processing.[7]

Case 4

AWS — Client tokens in the Amazon EC2 API

Some Amazon EC2 API actions, such as TerminateInstances, are idempotent by default. Others, including RunInstances, support idempotency through an optional client token. If a request that already succeeded is retried with the same token and the same parameters, it succeeds without performing any further action.[8]
Result: A client token is a case-sensitive string of up to 64 ASCII characters; reusing it with different parameters (other than Region or Availability Zone) fails with an IdempotentParameterMismatch error.[8]

Try it today

  1. Pick one POST endpoint in your API where a duplicate would cause real trouble, such as a payment or an order.
  2. Set a rule that the client generates a UUID for each operation and sends it in a request header. Reuse that key for retries of the same operation.[3][5]
  3. On the server, handle the key atomically so concurrent retries cannot both start the operation; store it with the response status code and body, and return the stored response when the same key arrives again.[4][6]
  4. If the same key arrives with a different request body, reject it with an error.[3][4]
  5. Decide how long keys are kept, document it, and schedule a job that deletes expired keys.[3]

Limits and direction

The idempotency key header is not yet a standard. The IETF Internet-Draft for the Idempotency-Key header (draft-07, October 2025) expired on April 18, 2026 without becoming an RFC.[3] As a result, rules differ by provider: Stripe allows keys to be pruned after 24 hours and Toss Payments keeps them for 15 days, while the AWS EC2 guide does not state a retention period; maximum key lengths are 255, 300 and 64 characters respectively.[4][5][8] If you switch payment providers, you cannot assume the same implementation will carry over.

Idempotent does not mean the response is always the same. HTTP defines idempotency in terms of the intended effect on the server, so a correctly built DELETE can return a success code the first time and 404 on later calls.[2] Stripe also states that results are saved only after endpoint execution begins, so requests that fail validation or conflict with a concurrent request are not saved and can be retried.[4] Write down your retry rules, including backoff, alongside the key design.[9]

Which sources explain Idempotency?

  1. IETF — RFC 9110: HTTP Semantics, STD 97 (2022-06) — https://www.rfc-editor.org/rfc/rfc9110.html
  2. MDN Web Docs — Idempotent (glossary) — https://developer.mozilla.org/en-US/docs/Glossary/Idempotent
  3. IETF — The Idempotency-Key HTTP Header Field, draft-ietf-httpapi-idempotency-key-header-07 (2025-10-15, expired 2026-04-18) — https://datatracker.ietf.org/doc/draft-ietf-httpapi-idempotency-key-header/
  4. Stripe — API Reference: Idempotent requests — https://docs.stripe.com/api/idempotent_requests
  5. Toss Payments Developer Center — Authentication and other headers: Idempotency-Key header — https://docs.tosspayments.com/reference/using-api/authorization
  6. Toss Payments Developer Center — What is idempotency? (2023-01-11) — https://docs.tosspayments.com/blog/what-is-idempotency
  7. Kakao Pay Tech Blog — Handling network exceptions well in an MSA environment (2022-05-25) — https://tech.kakaopay.com/post/msa-transaction/
  8. AWS — Ensuring idempotency in Amazon EC2 API requests — https://docs.aws.amazon.com/ec2/latest/devguide/ec2-api-idempotency.html
  9. Stripe — Brandur Leach, Designing robust and predictable APIs with idempotency (2017-02-22) — https://stripe.com/blog/idempotency