Kelly Mears

Idempotence

The property that performing an operation twice has the same effect as performing it once.

Systems & Tooling2 min read208 words13 out · 32 in
also calledIdempotent

Idempotence is the property that repeating an operation changes nothing further. Setting a value is idempotent; incrementing one is not. Creating a record with a caller-supplied identifier can be; creating one with a generated identifier is not.

It is the single most useful property in any unreliable system, because it makes retry safe. Networks drop responses, jobs get rerun, users double-click, and schedulers overlap. If the operation is idempotent, none of that requires coordination — which is why an idempotency key is standard practice in payment and messaging interfaces.

It also makes automation tractable. A provisioning script that can be run repeatedly is one you can run without thinking; one that fails or duplicates on a second run has to be reasoned about every time. The same applies to scheduled jobs, migrations, and imports: designing so that a double run is harmless removes an entire class of operational anxiety. See Cron and Database Migration.

The corresponding design work is usually to make the operation express the desired end state rather than a delta — write the value rather than adjust it, upsert rather than insert, and derive rather than accumulate. Where a delta is unavoidable, a caller-supplied key and a record of keys already seen restores the property.

See also11

Signaling Server

The small coordination service peers use to find each other before connecting directly.

Networks & Distribution10 connections

Race Condition

A defect whose occurrence depends on the relative timing of concurrent operations.

Testing & Verification36 connections

Determinism

The property that identical inputs produce identical outputs, and the foundation of caching and verification.

Systems & Tooling61 connections

Relational Database

Data organized as tables with declared relationships, queried declaratively and guarded by constraints.

Data & Content21 connections

Seed Data

Initial content created programmatically to make an empty system usable or demonstrable.

Data & Content14 connections

Conflict-Free Replicated Data Type

A data structure whose replicas can be edited independently and always converge without coordination.

Networks & Distribution12 connections

Eventual Consistency

A guarantee that replicas converge given no further updates, without guaranteeing when.

Networks & Distribution22 connections

WebRTC

The browser standard for direct peer connections carrying audio, video, and arbitrary data.

Networks & Distribution14 connections

Upsert

Inserting a row if it doesn't exist and updating it if it does, in one atomic statement, which is harder than it sounds because the obvious check-then-insert version races with itself.

Data & Content13 connections

Atomic File Write

Replacing a file so that readers and crashes see either the complete old version or the complete new one, never a half-written mix, by writing a temporary file and renaming it over the original.

Systems & Tooling12 connections

Idempotency Key

A unique token a client attaches to a request so the server can recognize a retry and return the original result instead of doing the work twice, the standard defense against double charges and duplicate orders.

Data & Content10 connections

Linked from32