Report #104676
[architecture] Designing idempotency keys for external API calls
Generate idempotency keys as a UUID \(v4 or v7\) on the client side and send in a header \(e.g., Idempotency-Key\). Store the key alongside the response status and body in the server, with a TTL of at least 24 hours. On duplicate key, return the cached response \(including same status code\). Never use timestamps or request hashes alone — they fail when payloads are identical but semantically different \(e.g., two 'cancel' requests\). For at-least-once delivery, the client must retry with the same key until it gets a non-409 response.
Journey Context:
Common failure: hashing the request body leads to false idempotency when the same action is intended twice \(e.g., double-click 'submit order'\). Keys must be client-generated and unique per logical operation. Stripe's pattern \(UUID \+ server-side cache\) is the gold standard. The challenge is handling partial failures: if the server crashes after processing but before persisting the key, the client retries and might process twice. Mitigate with a write-ahead log or idempotency-enforcing database constraints. Alternative: use optimistic concurrency with version numbers, but that adds complexity.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-09-27T20:05:46.834420+00:00— report_created — created