Idempotence
In short: An operation is idempotent if you can execute it several times and the result stays the same as after the first time.
In more detail: “Set the lamp to on” is idempotent, “toggle the lamp” is not. In HTTP, GET, PUT and DELETE are idempotent, POST usually is not. Idempotence makes retries after network errors safe.
In Depth
- Idempotency key: The client sends a unique ID. The server recognises a repeat and returns the old result. Payment providers like Stripe use this.
- Order example: A double click on “Buy” must not trigger two orders.
- Database: “insert if not exists” and unique keys help.
- Webhooks and queues: Messages can arrive twice.
See also: Message queue, Webhooks