computer science//idempotence

Idempotence is the property of an operation that leaves the system in the same state whether it runs once or several times with the same input. It is what makes retries safe: in any system where a message can be lost, duplicated or repeated after a timeout (a web API, a job queue, an MQTT link, an AI agent calling tools), an idempotent operation can simply be sent again.


Idempotence is the property of an operation that leaves the system in the same state whether it runs once or several times with the same input. It is what makes retries safe: in any system where a message can be lost, duplicated or repeated after a timeout (a web API, a job queue, an MQTT link, an AI agent calling tools), an idempotent operation can simply be sent again.

The everyday contrast is reading against moving money. Asking for an account balance twice changes nothing; sending transfer 100 euros twice sends 200. Setting a valve to 40 % open is idempotent, open the valve 10 % more is not, and a lost acknowledgement turns the second into a hazard, because the sender cannot tell whether the first copy arrived.

HTTP builds it into its methods. GET, PUT and DELETE are defined as idempotent, POST is not, which is why a browser warns before resubmitting a form. A payment API makes a POST safe with an idempotency key: the client attaches a unique id to the request, and the server that sees the same id twice returns the first result instead of charging again.

Delivery guarantees push the problem onto the receiver. A queue or broker that promises at-least-once delivery (MQTT at QoS 1, most job queues) will sometimes deliver twice, and only an idempotent handler, or one that records the ids it has already processed, keeps the effect single.

Absolute set-points are the industrial habit for the same reason. A controller that writes the target position, never a relative step, can repeat a write after a dropped packet with no harm.

Exactly once is a property of the effect, never of the wire.

Networks can only promise at most once or at least once; an operation becomes exactly once when it is made idempotent at the receiving end.

Idempotence is often confused with determinism (same input, same output); a deterministic append still grows the list each time it runs. In an agent loop the distinction decides which tools may be retried automatically and which need a check or a human first.