Hypothetical scenario. Northwind introduces a reservation action as a separate feature. A buyer’s request may have succeeded before its reply disappeared. Dev adds a table of seen identifiers; Priya starts two attempts before either has recorded completion.
Dev: “Both attempts found that the identifier was absent.”
Maya: “Where must the decision and the business effect become one protected operation?”
Build an operation state machine rather than a standalone seen flag. Bind identity to parameters, handle concurrent attempts and retain uncertainty across restarts. The reservation is an explicit new contract; it is not extra work silently inserted into the earlier browsing estimate.
Where can two attempts both decide to act?
A process checks whether an operation identifier exists, finds nothing and begins the reservation. Another process performs the same check before the first records completion. Both can now create effects. The existence of a deduplication table does not close the gap between checking it and changing the business state.
Recording the identifier after the effect leaves a crash window. Recording it before the effect and treating every record as completed can suppress work that never happened. The record therefore needs meaningful states, and its transition must be coordinated with the effect it represents.
A local memory cache cannot establish this property across independent workers or restarts. A shared cache may still have expiry, consistency or failure behavior that does not match the durable business operation. Choose the mechanism from the required effect boundary rather than from the convenience of a fast lookup.
Bind the operation to its meaning
A useful request contract carries a stable operation identifier scoped to the authenticated actor and operation type. The service binds that identity to the intended parameters. Reusing an identity for a materially different request should produce a conflict, not silently return the first request's result.
When the business effect and operation record share a database, a suitable transaction and uniqueness constraint can establish one accepted transition. Concurrent attempts must resolve the same identity under the selected isolation behavior. The loser then reads the recorded result or a declared pending state instead of creating another effect.
PostgreSQL's isolation documentation is a concrete reminder to inspect concurrency semantics rather than assume that any transaction prevents every anomaly. The application design here also requires the chosen uniqueness constraint and atomic update boundaries; isolation alone is not the whole protocol.
Bind retries to an immutable intention
Hypothetical scenario. Reserve one Q7 for tenant T under operation K. The authoritative record stores K, the caller scope, a canonical request fingerprint, state and recoverable result. An identical retry reads or completes the same intention; reusing K for two units is a conflicting request rather than another attempt.
| Stored field | Example | Purpose |
|---|---|---|
| Scope + operation | T / K | Tenant-bound intention |
| Fingerprint | Q7, quantity 1 | Reject changed meaning |
| State + result | accepted, reservation R | Recover lost response |
The claim operation and protected business transition must share an enforcement boundary. A separate check followed by an insert lets two callers both observe absence. A unique identity constraint can serialize the claim, but its winner must still execute the business transition under the required transaction or remote protocol.
Retention is a correctness input. After forgetting K, an old retry may look new. Define the supported retry horizon and how older requests are rejected, recovered from durable business identity or otherwise handled. A new attempt identifier is useful telemetry but must not replace K at the effect boundary. Authorization also needs a declared policy on retry: knowing K must not grant another tenant access to its receipt.
Count attempts, effects and retained identities
Hypothetical scenario. Choose 1,000 logical reservation requests. Eighty each receive one additional attempt after an uncertain response. The transport handles 1,000 + 80 = 1,080 attempts. If all requests are accepted and the effect boundary enforces the stated identity contract, the intended number of reservations remains 1,000.
The difference is 80 avoided extra effects under these assumptions, not 80 avoided network requests. The service still authorizes, looks up state and returns a result for retries. Resource planning must account for attempts even when the business effect is safely deduplicated.
For retention, choose 10,000 new operation records per day, seven days of supported retries and 300 bytes of logical record payload. The retained count is 10,000 × 7 = 70,000; payload is 70,000 × 300 = 21,000,000 bytes, or 21 MB using decimal units. Indexes, replica copies, storage allocation and larger result bodies are excluded.
If clients can retry after eight days but records expire after seven, the service has a one-day interval outside the promised deduplication coverage. It must reject expired identities, retain durable business uniqueness or state a narrower supported retry contract. Simply deleting the record cannot preserve an unlimited promise.
Now choose an external provider call that succeeds, followed by a crash before the local success record. Retrying creates another effect unless the provider accepts the same operation identity or the application can reconcile the existing action. A local database transaction cannot atomically include an arbitrary external service.
In the wild: a provider specifies the retry boundary
Stripe’s idempotent-request documentation specifies parameter matching, saved results and key-retention behavior for its API. The provider’s contract matters precisely because a local database cannot include an arbitrary external effect in its own commit. Northwind must inspect the contract for the API version and operation actually selected.
End-to-end effects cross local boundaries
For an external action, first establish what the provider promises about repeated identities, retention and parameter mismatch. Store enough request and result evidence to reconcile an uncertain outcome. A status query can help only if it identifies the same operation reliably; searching for a similar amount or timestamp is not equivalent.
An outbox coordinates the database change and intent to publish. It does not by itself make a downstream payment, email or shipment occur once. The recipient must handle repeated deliveries at its own effect boundary. This connects directly to the queue lesson's distinction between acceptance, processing and business completion.
Sometimes the appropriate operation is naturally state-setting rather than additive. Repeating “set the preferred locale to this value” can preserve the same intended state, while repeating “increment the credit balance” generally cannot. Concurrent legitimate changes still require an ordering or conditional update rule.
The key is reused for another purchase
Hypothetical failure scenario. A mobile client reuses its previous operation identifier for a different item. The server finds a completed operation and returns its receipt without comparing request meaning. The new purchase appears successful even though the receipt describes another action.
Bind identity to canonical operation parameters and reject incompatible reuse. Canonicalization itself must preserve distinctions that matter to the business, such as item identity, currency or quantity. Blindly hashing a raw serialization can also treat semantically identical representations as different operations.
Authorization remains necessary on every attempt. Scope records to the actor and tenant, prevent cross-tenant receipt lookup, and avoid exposing sensitive results through a guessed identifier. Deduplication is a correctness tool, not proof of permission. Audit records should identify who requested and authorized the action while limiting sensitive payload retention.
Avoid the once-only slogan
“The handler ran once.” It may run repeatedly while one transactionally protected effect is accepted. State which effect the contract covers.
“A new key makes a retry safe.” A new key generally represents a different operation to the deduplication mechanism. Preserve identity across attempts of the same intention.
“An HTTP method proves the application implementation is safe.” RFC 9110 defines method idempotency in terms of intended server effects. A method label does not repair a handler that violates its semantics or establish a separate business workflow's deduplication policy.
Use identity where uncertainty can repeat effects
Use explicit operation identity when callers may repeat an additive action after uncertainty. Declare scope, parameter binding, concurrent behavior, retention, pending states and recovery. Show callers how to distinguish an accepted operation from a completed downstream effect.
Do not turn every read into a durable operation record without a reason. Nor should an idempotency layer hide business conflicts: two different users can legitimately submit distinct operations that compete for the same inventory. The invariant still needs an atomic reservation decision.
Limits of the guarantee
This design relies on enforced uniqueness, guarded transitions and a provider contract that can identify the original effect. Lease timeouts, cache expiry and HTTP method names alone establish none of those properties. The arithmetic is hypothetical, and retained payload estimates exclude indexes and logs. Define what happens after the provider’s recognition window, during reconciliation outages and when an action cannot be safely retried.
Challenge the proposed mechanism
The old identity record expired, but a client retries with K. May the service simply create another reservation?
Reveal the design reasoning
Only if the published contract explicitly permits that business outcome; ordinary deduplication does not. Prefer a durable business link or reject requests beyond the supported horizon. Include expiry and restore in the duplicate-effect analysis.
Decision and reconsideration: Keep business identity independent from attempts. Review retention, tenant scope and uncertain-state recovery as part of the guarantee.
Resolve repeated attempts
Two workers both read an absent identifier. Can each proceed?
Make acquisition atomic
No. A uniqueness constraint and coordinated effect transition must select the accepted operation. Separate reads of absence leave a race, and recording completion afterward leaves a crash window.
The external action completed but the local success record is absent. Is another action safe?
Keep the unknown outcome visible
Absence of the local result does not establish absence of the effect. Reconcile the same provider identity or use its supported safe retry contract. A local ownership lease expiring is not evidence that the previous external call failed.
A matching identity arrives with a different quantity. Should the old receipt be returned?
Bind identity to intent
No. Reject conflicting parameter reuse. A deliberate new purchase needs a deliberate new logical identity; recovery of the existing operation keeps the old identity.
Stable operation identity prevents one intention from multiplying its effects only under the selected protection boundary. Page 28 examines the local transaction and the business invariants that boundary must preserve.
Northwind decision log
Bind tenant, action, identity and material parameters before accepting an effect.
Preserve unresolved external outcomes beyond ordinary cache expiry.
Next, protect the business invariant when distinct legitimate operations compete.
Go deeper: recovery across effect boundaries
- Book chapter: Principles of Transaction Processing, second edition, chapter 4: Queued Transaction Processing — Philip A. Bernstein and Eric Newcomer. Examine client recovery and non-undoable operations.
- Book chapter: Principles of Transaction Processing, chapter 5: Business Process Management — the same authors. Connect durable progress to recovery. Use current provider documentation for implementation details.
- Video lecture: Distributed OLTP Database Systems — CMU Database Group. Inspect transaction boundaries when work crosses participants.
- Primary document: Idempotent requests — Stripe. Compare identity, parameter binding and retention with an actual API contract.