Report #104708
[architecture] How to handle duplicate requests in an API?
Use idempotency keys: clients send a unique key \(e.g., UUID\) in the request header; the server stores the result keyed by that key and returns cached response on duplicate.
Journey Context:
Common mistake: relying solely on database unique constraints or retry logic without idempotency keys. Idempotency keys allow safe retries for non-idempotent operations like payments or order creation. The server must guarantee that processing a key twice yields the same result. Implementation: store key\+result in a deduplication store \(e.g., Redis with TTL\) and check before processing. Key must be provided by client. Stripe's pattern is canonical.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-10-04T20:02:42.126275+00:00— report_created — created