Idempotency
Description
Idempotency is the property that applying an operation N times produces the same outcome as applying it once. f(f(x)) = f(x). The diagnostic shape: an operation’s behavior depends only on the destination state, not on whether it’s the first, second, or hundredth time the operation has been requested. The structural payoff is that retries become safe — duplicate requests, network re-sends, replay attacks, and consumer re-processes all converge on the same end state. Idempotency is the structural enabler underneath retry-safe distributed systems. Without it, at-least-once delivery (the only guarantee most systems can offer) becomes a footgun: every duplicate is a double-charge, a double-book, a duplicate-row, a retry-storm. With it, at-least-once is semantically equivalent to exactly-once at the application layer.Triggers
User-initiated: User describes a system where retries cause duplicates, or proposes adding retry logic without considering whether the underlying operation is safe to retry. Vocabulary cues: “idempotent,” “retry-safe,” “exactly-once,” “deduplication,” “upsert,” “apply twice.” Agent-initiated: Engine notices a system where retries are proposed but the underlying operation isn’t naturally idempotent — duplicate-charge risk, double-book risk, double-send risk. Candidate inference: “this operation needs an idempotency key, OR it needs to be restructured as a set-state operation rather than a delta-state operation.” Situation-shape signals: Distributed system with at-least-once delivery; user-facing operation that must not duplicate (charges, bookings, sends); network-flaky operation where retries are expected.Exclusions
- Genuinely delta-based operations — “transfer $100 from A to B” is not naturally idempotent; you either wrap it in an idempotency-key envelope or accept the at-most-once delivery cost.
- Side-effects on external systems you don’t control — sending an email is not idempotent; the recipient sees N emails. You either dedupe before sending or accept the duplicate cost.
- Time-dependent operations — “log current timestamp” is not idempotent by construction; re-running produces a new value.
- Cache-warming / load-shedding — sometimes the cost of an operation matters more than its outcome; the first call is cheap and the Nth call might thrash. Idempotency-of-outcome doesn’t imply idempotency-of-cost.
Structure
Relationships
- retry-with-backoff — idempotency is what makes retry safe; without it, backoff just delays the duplicates.
- make-wrong-unrepresentable — both are structural-correctness moves; idempotency makes duplicate-application equivalent to single-application.
- bookends — idempotent operations are often a single bookend-pair (open / close); re-opening a closed bookend pair is a no-op.
Examples
Light switches · engineering-and-technology
Light switches · engineering-and-technology
Surgical "time-out" protocol · medicine-and-health
Surgical "time-out" protocol · medicine-and-health
algebra: an element x where x·x = x; mathematical lineage from group theory · mathematics
algebra: an element x where x·x = x; mathematical lineage from group theory · mathematics
Database UPSERT · computer-science
Database UPSERT · computer-science
DNS A-record updates · computer-science
DNS A-record updates · computer-science
Double-entry bookkeeping · business
Double-entry bookkeeping · business
Git commits · computer-science
Git commits · computer-science
Helland, *Life beyond Distributed Transactions* (2007) — the architectural argument for idempotency as the alternative t · computer-science
Helland, *Life beyond Distributed Transactions* (2007) — the architectural argument for idempotency as the alternative t · computer-science
idempotency primitive is not a quality-of-implementation detail but a requires-relationship anchor — retry-with-backoff, event-sourcing, and saga all require idempotency to be safe. Naming the architectural cost-shift — pay the cost of idempotency-key design upfront, save the cost of distributed transactions forever — clarifies why this concept is worth the curatorial weight.HTTP PUT vs POST · computer-science
HTTP PUT vs POST · computer-science
HTTP RFC 7231 §4.2.2 — the canonical formal definition for web APIs. · computer-science
HTTP RFC 7231 §4.2.2 — the canonical formal definition for web APIs. · computer-science
Kleppmann (2017), Designing Data-Intensive Applications, Chapters 8, 11; Hello Interview primer on idempotency; HTTP RFC 7231 §4.2.2 (idempotent methods) · computer-science
Kleppmann (2017), Designing Data-Intensive Applications, Chapters 8, 11; Hello Interview primer on idempotency; HTTP RFC 7231 §4.2.2 (idempotent methods) · computer-science
Stripe API idempotency keys · computer-science
Stripe API idempotency keys · computer-science