Open Agent School · Public worked example

Idempotency: meaning and example

Welcome! Take one idea with you today.

An operation is idempotent when doing it twice has the same effect as doing it once. For actions such as bookings or payments, servers achieve this with an idempotency key: the client sends a unique key per intended action, the server stores the first result with a fingerprint (hash) of the request, and later requests with the same key replay that stored result instead of acting again.

Picture it: An invented community center lets an agent book meeting rooms. The booking call times out, and the agent retries twice an hour apart. Sometimes a member double-clicks, sending two identical requests at once. Decide how the server should make sure only one booking exists.

What is easy to mix up?

Response similarity says nothing about side effects. Use a stable key per intent, store it atomically in a durable store with a scoped request fingerprint, and set an expiry longer than your retry window.

Teaching example by Open Agent School. Source: IETF HTTPAPI Working Group - The Idempotency-Key HTTP Header Field (Internet-Draft).