What idempotency means
An operation is idempotent when applying it many times has the same effect as applying it once. In a distributed system, networks drop responses, so a client cannot always tell whether its request succeeded. The safe answer is to retry, and idempotency makes retries harmless.
Natural versus engineered
- Some operations are naturally idempotent, like setting a field to a fixed value or deleting a known record.
- Others are not, like adding to a balance or appending to a list. Each replay changes state again.
To make a non idempotent action safe, attach an idempotency key, a unique token the client generates per logical request. The server records the key and its result. If the same key arrives again, it returns the stored result instead of repeating the work.
Why it matters
Without idempotency, a retried payment can charge a card twice, or a retried order can ship two parcels. Idempotency turns an unreliable network into a reliable one from the caller view.
Key idea
Idempotency lets a client retry safely after an uncertain outcome, usually by recording an idempotency key and returning the saved result for repeats.