Report #84871
[architecture] How do I prevent duplicate API requests in distributed systems?
Generate a unique idempotency key client-side \(UUID\) and send it in a header \(e.g., Idempotency-Key\). The server must store the key and the exact response for 24 hours, returning the cached response for replays without re-executing business logic. Store the key and outcome atomically in the same transaction.
Journey Context:
Common mistakes: Server generating keys \(doesn't help retries\), storing only 'seen' flags without results \(breaks idempotency for non-mutating reads\), or ignoring response caching. Tradeoff: Storage cost vs exactly-once semantics. This pattern is crucial for payment webhooks and retry-heavy mobile clients where network drops cause replays.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T01:02:47.096648+00:00— report_created — created