veda.ng
Back to Glossary

Idempotency

Idempotency is the property where performing an operation multiple times produces the same result as performing it once, making the operation safe to retry without causing unintended side effects. HTTP GET requests are inherently idempotent: fetching data doesn't modify it, so fetching repeatedly returns the same state. DELETE with a specific resource ID is idempotent: whether you delete once or ten times, the resource ends up deleted. PUT replacing a resource with specific content is idempotent: the final state is the same regardless of repetition. POST creating new resources is typically not idempotent: posting twice creates two resources. Network failures make idempotency critical for distributed systems. If a server processes a request but the response is lost in transit, the client doesn't know if it succeeded. Without idempotency, retrying might duplicate the operation such as transferring money twice, creating duplicate orders, or sending duplicate emails. Idempotency keys solve this for non-idempotent operations: the client generates a unique ID for each logical operation and sends it with every request. The server tracks completed operations by key; duplicate requests return the cached result instead of re-executing. Payment systems require idempotency keys. Message queues use them for exactly-once delivery guarantees. Building reliable distributed systems requires thinking carefully about idempotency at every integration point.