Idempotency means repeating an operation has the same intended effect as doing it once. If a reply is lost, the first call may have worked. Setting a flag to true is repeat-safe; adding one to a counter is not, so each API needs a clear retry contract.
What idempotency means in software
The practical idempotency meaning concerns the requested effect. It does not mean code runs once. RFC 9110, section 9.2.2, makes that distinction for HTTP methods.
A server can log each call or keep a change history.
A mathematical idempotent function gives the same value when applied again to its output. For software, name the state and task you mean. A message sent twice to a later service may fall outside that scope.
An idempotent API need not send the same reply each time. It can change state. Test the business result, not just the status code.
Which HTTP methods are idempotent?
RFC 9110 and MDN distinguish safety from repeat effects. A safe method asks for no state change. The server may still write logs.
| Method | Safe by HTTP rules? | Idempotent by HTTP rules? |
|---|---|---|
| GET, HEAD, OPTIONS, TRACE | Yes | Yes |
| PUT, DELETE | No | Yes |
| POST, PATCH | Not generally | Not guaranteed |
PUT asks to create or replace the target state. DELETE asks to remove the link between a resource and its current function. It does not promise to erase all stored copies.
These are method rules, not proof that a route works. A server must honor them.
A hypothetical DELETE might first return success. The next call could report that the resource is absent. The reply differs, but removal remains the intended effect.
POST and PATCH can have repeat-safe designs for a given route. Their names alone give no such promise. RFC 9110 says clients should not retry them on their own unless the semantics are known to be idempotent or the first request was not applied.
A timeout alone proves neither condition.
Follow one lost response through a retry
Take a hypothetical order API that supports an idempotency key. The client sends an order. The server saves it, but the reply is lost.
The client knows the call timed out. It does not know if the order exists. It must not treat a missing reply as a failed order.
To retry the same task, keep the key and payload. Under this API’s rules, the server spots the repeat. It returns the stored result without adding a second order.
A fresh key on each attempt names new work. One key for two distinct orders creates the opposite fault. The second valid order may be lost as a supposed repeat.
Matching contents do not prove matching intent. Assign an operation ID before the first call. Keep it across restarts for this proposed design.
Give callers a way to check the result. Bound the number of attempts. A repeated call cannot prove that the first one failed.

Original illustration; hypothetical workflow.
What an idempotency-key implementation must specify
An Idempotency-Key header works only when the server supports it. These are design rules to test. They are not tested code or a claim about a universal header standard.
Request identity and scope
Scope the identity by caller or tenant, task, and key. State which payload fields must match. Reject changed data under the same identity.
Define how long the record lives. Tell callers what a retry means after that time.
Claim a key in one atomic storage step. A separate “check, then insert” can race. Two workers may both find no record.
PostgreSQL unique constraints show how storage can enforce a unique value or group of values. Be careful with nullable fields. By default, null values are distinct for this rule.
Our database-indexing guide explains lookup and write costs. An index can help find a key. That alone does not define a safe claim.
In-progress, completed, and uncertain work
Say what a second caller sees while work runs. It might wait or get a defined retry reply. Do not silently start a second effect.
Save enough data to meet the replay rules once work ends. AWS Powertools Python 1.31.1 documents an already-in-progress error. This is an older, pinned example, not a current SDK recipe.
Database transactions group local changes into an all-or-nothing step. That promise does not cover a call to an outside provider. Calling it from inside the block does not bring it into the database.
A crash may follow the outside effect but precede the saved result. Mark that outcome as unknown. Check the provider’s receipt before deciding what to repeat.
Payload mismatch and expiry
Stripe’s contract saves the first status and body once endpoint execution starts. This includes 500 errors. It also checks that parameters match.
Stripe can prune keys once they are at least 24 hours old. Reuse after pruning creates a new request. This is Stripe’s rule, not a universal time limit.
Validation failures or conflicts with work still running can occur before execution starts. Stripe does not save those as an idempotent result. Those calls can be retried.
Define your own failure and expiry rules for a custom API.

Original illustration; hypothetical workflow.
A failure matrix to test your retry contract
Use this proposed test plan with faults you control. Write the expected effect and reply before each test. This is not proof of end-to-end exactly-once delivery.
| Test | Effect to check | Reply to expect | Record to inspect |
|---|---|---|---|
| Two calls in a row, same identity | One order | Defined replay | Order ID and saved result |
| Two calls at once | At most one accepted effect | Replay or in-progress reply | Claim and effect IDs |
| Same key, changed payload | No second effect | Mismatch rejection | Payload check |
| Reply lost after commit | Keep first effect | Recover or replay | Commit and operation ID |
| Failure before local commit | No committed local effect | Defined failure/retry | Rollback and key state |
| Crash after outside effect | No blind repeat | Unknown until checked | Provider receipt |
| Pruned key reused | May be new work | Expiry rules apply | Key age and prune time |
| New valid task | Separate effect | New result | Distinct identity |
Count orders or other business effects, not just calls. Check the returned ID when replay must retain it. Read both the key record and the business state.
Make workers overlap at the claim step to test a race. Restart a worker at each crash boundary. Test the edge of the real retention window, not just a fresh key.
Keep useful traces without full personal payloads or secret keys. Preserve an unknown outcome when the evidence is weak. Idempotency in software reaches only as far as the scope you define and test.

Original illustration; proposed tests, not results.
The Alex Hyett video gives a teaching overview of methods and keys. It does not prove this design has been run.



