Card 06/ 06
Recap: Idempotency Keys
A key turns a write that is not idempotent into one that is, if it is stored before the work starts.
A timeout hides whether a write happened, and a key makes the retry safe either way.
- Same write twice comes from timeouts, lost responses, and retries by libraries, proxies and queues.
- POST and PATCH need a key when repeating them would cost something; GET, PUT and DELETE do not.
- The key is a random value per operation, sent in
Idempotency-Key, reused on every retry. - The server records the key before acting and returns the stored response to a repeat.
- Scope, expiry and fingerprint: per client, for a stated window, bound to the first request.
- Misuse: 422 for a different body, 409 while the first is running, 400 for a missing key.
- The race: record the key with an atomic insert, or two copies both act.
← → move through sections and cards