Report #92445
[architecture] Preventing duplicate API operations during retries with idempotency keys
Require clients to generate a unique idempotency key \(UUID v4\) for every mutating request; store the key with the response payload server-side with a TTL \(e.g., 24h\), and return the cached response for duplicate keys without re-executing the operation.
Journey Context:
Network timeouts cause clients to retry, leading to double-charges or duplicate writes. Server-side checks \('did I already process this?'\) fail across distributed nodes or after restarts because there's no shared state. The idempotency key pattern separates identification from execution: the client generates a unique key \(opaque string\) and sends it in a header \(e.g., Idempotency-Key\). The server stores the mapping \(key → response\) atomically before executing the business logic, with a TTL to bound storage. On duplicate requests, the server returns the stored response \(including original status codes\) without side effects. Critical mistakes include: server-side key generation \(defeats purpose, client can't retry\), missing TTL \(unbounded storage growth\), and applying to non-idempotent sequences \(e.g., 'increment counter' without read-modify-write isolation\).
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T13:45:45.550196+00:00— report_created — created