What is Idempotency?

Idempotency is the property that repeating the same operation has the same intended effect as performing it once. Setting a backup job to “enabled” is idempotent: repeating the setting leaves it enabled. Creating another backup job each time is not.
The distinction matters when a request succeeds but its response is lost. A timeout tells the caller that it did not receive an answer in time. It does not establish whether the server accepted the work. Idempotent operations let software handle that uncertainty without adding another intended action on every attempt.
For a UK home lab, that might mean avoiding duplicate cloud backup jobs after a connection interruption. For an application, it might mean recognising a repeated order submission or webhook. Faster broadband cannot settle which action a remote application has already committed.
What does idempotency actually guarantee?
An idempotent operation can execute more than once. The important property is what repetition does to the state or business effect being protected. It is therefore essential to name that effect: one job created, one reservation recorded, or a configuration value set to a specified state.
For a simple state transformation f, the mathematical test is f(f(s)) = f(s). Applying the transformation twice reaches the same state as applying it once. Real applications complicate this model with other writers, timestamps, notifications and work in other systems. A useful guarantee defines its scope rather than claiming that absolutely nothing changes anywhere.
Same effect does not mean same response
An initial deletion might report success and a later identical deletion report that the resource is absent. The requested absence is unchanged. Request logs and tracing records may also grow with each attempt.
The HTTP semantics standard defines idempotency around the intended server effect, rather than identical response bodies. A service may additionally promise to replay a stored response, but that is an extra API contract.
A small executable example
This Python example changes only an in-memory dictionary. Running it creates no files and calls no services.
state = {"enabled": False, "jobs_created": 0}for attempt in range(3): state["enabled"] = True state["jobs_created"] += 1assert state["enabled"] is Trueassert state["jobs_created"] == 3print(state)
The final value is enabled=True and jobs_created=3. Assignment expresses a desired state. Incrementing a counter expresses another change each time. An API that starts work needs an additional identity or business constraint if three attempts should represent only one job.
Which HTTP methods are idempotent?
HTTP method semantics provide a starting point. Safe means that the requested operation is essentially read-only. An idempotent operation can deliberately change state.
Method | Idempotent by defined semantics? | Practical interpretation |
|---|---|---|
GET and HEAD | Yes; also safe | Read a resource; returned content can change |
PUT | Yes | Set the target resource to the supplied state |
DELETE | Yes | Remove the target resource's association |
POST | Not generally | Read the operation's explicit repeat contract |
PATCH | Not generally | Examine the patch instructions and safeguards |
A method name cannot repair an implementation that creates unintended duplicate work. Conversely, a particular POST operation can support safe repetition through an explicit application contract.
RFC 5789 specifies PATCH separately. A patch that sets a field to a fixed value can be designed to be idempotent; an instruction that appends an entry can add another entry on repetition. Partial modification and idempotency are different properties.
How do idempotency keys work?
An idempotency key identifies a logical operation across attempts. The client creates it before the first submission, retains it, and supplies it again when repeating that operation. The server recognises the identity and follows its documented policy instead of blindly executing another action.
The AWS explanation of idempotent API design distinguishes caller-supplied intent from merely matching request parameters. Two identical requests might legitimately ask for two separate resources. A stable operation identifier lets the caller express which situation applies.
Imagine a backup client submitting snapshot A. Its first request creates job 41, but the response is lost. Retrying with the same operation key should find job 41 under the server's contract. A deliberately requested second backup needs a new operation identity, even if its settings match.
This complements retry logic: the retry policy controls timing and stopping, while the operation contract determines what repetition means. Neither replaces the other.

Identity needs more than a random string
A key should be unique for the operation in its documented namespace. Persist it with the client-side task so that a process restart does not accidentally turn a retry into a new operation. Do not generate a fresh key inside every retry iteration.
Contract detail | Question to answer | Failure if overlooked |
|---|---|---|
Scope | Which authenticated caller and operation does it belong to? | Collisions or cross-account result exposure |
Input binding | Which method, target and payload fields must match? | One key reused for different work |
Persistence | Does the record survive process restarts? | A restart forgets completed operations |
Concurrency | What happens while the first attempt runs? | Two workers both perform the effect |
Retention | How long is the identity remembered? | A late retry becomes new work |
Result policy | What is returned for success, failure or partial work? | The caller misinterprets the outcome |
A payload fingerprint helps detect accidental key reuse with changed input. It does not establish that two matching payloads represent the same intention. Nor does an untrusted caller-supplied account name establish authorisation. Derive the security scope from authenticated context.
Choose retention around the latest legitimate repeat: automated retries, offline clients, queued redelivery and manual recovery can have different timescales. Keeping records longer costs storage and may retain sensitive results; forgetting them sooner reduces the protection window. If a repeat can arrive after that window, preserve a longer-lived business identity or reconcile before executing again.
Be explicit about input normalisation. JSON objects with different key ordering can represent the same data, while omitted fields and explicit defaults may or may not be equivalent. Hashing bytes without defining the comparison policy can reject valid repeats or miss a meaningful change. Include the operation target and relevant version where the contract needs them.
Idempotency is not content deduplication
Content deduplication asks whether stored content already exists. Operation deduplication asks whether this particular requested action has already been accepted. Two backup jobs can reference identical bytes while being separate operations.
The distinction also matters for data integrity. A matching digest can help check content or compare input, but it does not prove that the correct number of business actions occurred.
Why a key lookup followed by a write can still duplicate work
Consider two workers handling the same key. Each checks the request table and finds no record. Both create a job, then try to save the key. A unique constraint on the key may reject one record, yet the second job may already exist.
The protected mutation and the evidence that it occurred must share a correctness boundary. In our local example, both are rows in one SQLite database, so a single transaction can cover them. An in-memory dictionary or a “check first” query outside that transaction cannot provide the same guarantee.
The local transaction sequence we tested
Our harmless job ledger uses a composite primary key containing scope and operation key. It stores the input fingerprint and original job identifier alongside it. The job row represents acceptance of work, not completion of a real backup.
Open a connection and start a BEGIN IMMEDIATE transaction.
Look up the scoped key inside that transaction.
If present, reject changed input or return the recorded job identifier.
If absent, insert the job and its request record in the same transaction.
Commit before returning an accepted result; roll back on an error.
SQLite documents that BEGIN IMMEDIATE starts a write transaction immediately. Other writers must wait or encounter a busy condition. Our test connection timeout was 10 seconds; production code needs explicit handling for storage errors, contention and its own deadline. This small demonstration is not a production queue or a multi-region database design.
The database constraint remains useful, but the essential difference is that an unsuccessful transaction cannot leave a separately committed extra job. A uniqueness conflict must not be swallowed after an irreversible action has already taken place.
What our concurrency and crash tests found
Techie Broadband ran a disposable local experiment on 24 October 2026 using Python 3.12.14 and SQLite 3.53.1. The databases used DELETE journal mode and synchronous=FULL. All 15 assertions passed, including the checks that deliberately demonstrate unsafe behaviour.
The racy version forced two workers through the initial empty lookup before either proceeded. The transactional version released two workers together and used separate connections. We counted actual job rows as well as deduplication records, rather than treating a successful key insertion as proof that nothing duplicated.
Test | Observed result | Meaning within this experiment |
|---|---|---|
Same scoped key and payload repeated | 1 job; original identifier returned | Repeat found the saved operation |
Same key with changed payload | Rejected; still 1 job | Input binding prevented different work |
Naive concurrent check then act | 2 jobs; only 1 key record | Unique key storage alone was too late |
Concurrent attempts in one transaction each | 1 job; both obtained the same identifier | Work and its evidence stayed together |
Child process exited before commit | 0 jobs after recovery; 1 after retry | Uncommitted work rolled back |
Child process exited after commit, before returning | 1 job before and after retry | A missing acknowledgement did not add a job |
Deduplication record deliberately deleted | Same key produced a second job | Forgetting identity ended that protection |
Other checks confirmed that opening a fresh connection preserved replay, that a new key created a second intended job, and that the same string in a different trusted scope represented a separate operation.
What these results do not prove
The process-exit cases terminated a child process with exit code 23 at controlled points. They tested recovery from that interruption, not a power failure, faulty disk or every possible crash schedule. FULL is a setting we recorded, not evidence that the underlying hardware was independently validated.
The experiment used no cloud API, payment service, real backup or message broker. It shows the consequences of transaction placement in this local design. It does not establish a universal throughput figure, service availability guarantee or exactly-once delivery system.
What happens when the effect is outside the database?
A database transaction does not automatically include an email server or a remote API call. If the remote action commits and the local process fails before recording that outcome, a retry can repeat the remote action. Reversing the order creates a different risk: recording “complete” before doing the work can suppress work that never happened.
We demonstrated the first gap with two independent local ledgers. One represented a remote receiver; the other represented the caller's deduplication record. These were separate local database commits, explicitly a simulation rather than a real remote-service test.
Stage in the two-ledger simulation | Receiver effects | Caller records |
|---|---|---|
Receiver committed; caller bookkeeping was skipped | 1 | 0 |
Caller retried because it had no record | 2 | 1 |
The lesson is to inspect where the effect is accepted, not just where a key is cached. A receiver-supported operation identity can close this particular gap if its scope, retention and failure contract cover the retry. Otherwise use reconciliation, a recoverable workflow or a business constraint appropriate to the action.
Inbox and outbox patterns
An inbox records a received message identity together with the local state change it triggers. An outbox records an event to be sent in the same transaction as the business change. A relay then delivers the event separately.
Chris Richardson's transactional outbox pattern explicitly notes that the relay can publish more than once if it crashes between delivery and recording progress. The receiver still needs to handle repetition. Moving delivery into a worker makes recovery manageable; it does not make the network and database a single atomic transaction.
Creating one accepted job also does not ensure that every later step of that job runs once. A backup worker, notification worker and billing integration each need a suitable boundary for their own effects. Define which stages can repeat, which can resume, and which require reconciliation.
In-progress records and leases
A long-running action often needs an in-progress state instead of holding a database transaction open throughout the work. The AWS Lambda Powertools Python utility, for example, protects concurrent identical invocations with an in-progress record and reports an already-in-progress error while the first is active.
Expiry needs careful interpretation. An expired worker lease means ownership may need recovery; it does not prove that the original effect never happened. Prevent a slow old worker and its replacement from both committing, using a conditional ownership/version check at the destination or another appropriate coordination design. A local lock cannot control an unrelated remote service.
Are conditional requests another form of protection?
Conditional requests guard the resource state on which an operation depends. If-Match checks a representation's entity tag; If-None-Match: * can require that a representation is absent. A failed state-changing precondition normally returns 412.
Mechanism | Question it answers | Important limit |
|---|---|---|
Operation key | Have we accepted this logical operation? | Only within its documented scope and lifetime |
Version precondition | Is the resource still the version I expected? | Does not identify who made an earlier change |
Business uniqueness rule | May this business entity exist twice? | Must reflect the real business invariant |
Google Cloud Storage documents generation-match preconditions for writes and deletes. Targeting a specific object generation can prevent a delayed repeat from affecting a replacement object. This is a useful example of attaching a request to the version it was meant to affect.
After an uncertain write, a failed precondition alone does not prove that your earlier request succeeded. Another actor might have changed the resource. Read the current version and reconcile it against the operation's identity and expected state before deciding what to do next.
Idempotency also does not solve lost updates between different operations. Two users can each issue an individually idempotent “set configuration” request, yet a later request can overwrite the other's change. Version checks address that separate concurrency problem.
Do all APIs remember keys and return results the same way?
No. The current Stripe idempotent request documentation illustrates why the API version matters. As checked on 24 October 2026, API v1 stores the first executed response, including a 500 error. It can prune keys once they are at least 24 hours old; reuse after pruning can start a new request.
Stripe v1 also checks parameter consistency. Validation failures and concurrent conflicts before endpoint execution do not store that executed result. Its API v2 contract differs: retries do not repeat successful operations, but can finish failed or partial work where possible and return an updated response.
Do not generalise one product's response cache, expiry period or error behaviour to another. Read the exact operation and version contract. A header named Idempotency-Key has no protective effect unless the receiving service actually implements it.
Where does this matter for a UK home lab?
For a NAS uploading to cloud storage, separate transfer progress from the action that finalises the backup. A client may safely replace a particular temporary object yet duplicate a “create backup” action afterwards. Stable snapshot and operation identities can help the receiver distinguish a resumed upload from a new requested backup.
Higher upload speed can shorten the transfer, but it does not remove the acknowledgement gap after the server accepts it. A dropped session, a client restart or a service timeout still requires application-level recovery.
For webhook delivery, use the source's documented event identity within a trusted source/account scope. Record acceptance durably and apply local changes with suitable deduplication. Delivery attempts and business events are not necessarily the same identity, and different events can concern the same object.
Deduplication does not establish ordering. A later status event might arrive before an older one, even when each is processed only once. Where the source supports versions or sequence information, check those separately; otherwise fetch authoritative state or use a reconciliation policy suitable for the integration.
Configuration automation offers another distinction. “Ensure this rule exists” can converge to a desired state; “append this rule” can add duplicates. Repeated restarts, notifications or generated timestamps inside a script may remain non-idempotent even when one configuration assignment is idempotent.
How should you troubleshoot duplicate actions?
Start with the accepted business effect and work backwards through its identity. The request count alone is insufficient: several attempts can correctly resolve to one operation, while a single accepted job can later trigger duplicate downstream work.
Record a logical operation identifier separately from each attempt's trace identifier.
Compare the authenticated scope, operation target, payload fingerprint and key across attempts.
Count committed effects and link them to the operation record, rather than counting successful HTTP responses.
Check the transaction boundary, record retention and any in-progress ownership changes.
Inspect downstream retries and manual recovery actions as well as the original client.
Avoid putting passwords, tokens or personal information in keys and logs. A key is an identifier, not an authentication credential. Check authorisation before replaying a stored result, minimise retained response data and protect the persistence layer from unauthorised access.
Bound key sizes, retention and request rates so the deduplication store cannot grow without control. If the store is unavailable, do not silently drop the protection and execute an irreversible action anyway. Return an appropriate failure or use an explicitly designed recovery path. Document that behaviour for callers.
When evaluating an “exactly once” claim, ask which effect it covers, where acceptance is recorded, how concurrent attempts are resolved and how long the evidence lasts. Idempotency can make repeated delivery harmless within that boundary. It does not by itself ensure that work eventually completes.
Our networking terminology guide connects these application behaviours with the networking and storage concepts around them. Reliable recovery depends on understanding each layer's evidence, rather than treating every timeout as a failed action.
Frequently asked questions
What is idempotency in simple terms?
Idempotency means repeating the same operation has the same intended effect as doing it once. Setting a value to “enabled” is a simple example. Repeated attempts may still produce separate logs or different responses.
Is idempotency the same as exactly-once execution?
No. An idempotent operation may execute repeatedly without adding another intended effect. Exactly-once claims need a defined effect and processing boundary. Idempotency alone also does not guarantee that the operation will eventually complete.
Is POST always non-idempotent?
POST is not generally idempotent by HTTP method semantics, but a particular API operation can provide an idempotent contract. Check its supported keys, input checks, concurrency behaviour, retention and failure responses before retrying it.
Should every retry use a new idempotency key?
No. Reuse the same key for attempts at the same logical operation within the service's contract. A new intended operation needs a new identity. Generating a fresh key for every attempt can turn retries into duplicate actions.
What happens when an idempotency key expires?
The service may stop recognising a later request as a repeat and treat it as new work. The exact behaviour depends on the API. Do not assume a key protects an operation forever or start a new action before reconciling an uncertain result.
Does idempotency prevent duplicate webhook processing?
It can prevent additional effects when a repeated event is identified and recorded with the state change it triggers. It does not authenticate the webhook, guarantee delivery order or automatically protect actions performed in a separate system.

