Report #15084
[architecture] Handling duplicate API requests in distributed systems without accidental double-charges or double-processing
Require clients to generate a UUID v4 idempotency key for mutation requests; store the key server-side with the response payload and a 24-hour TTL; reject requests with reused keys but mismatched payloads to prevent replay attacks.
Journey Context:
Teams often try to use database unique constraints on business keys, but this couples schema evolution to idempotency logic and fails for 'create' operations where the ID is server-generated. Others store keys forever, creating storage exhaustion. The correct approach treats the idempotency key as a transient lock: accept the first write, cache the exact response, and return that cached response for duplicates within the TTL window. This requires payload hashing to detect malicious replays with different request bodies. Redis or similar is preferred over database tables for this hot-path lookup to avoid write amplification on your primary database.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T23:12:31.620799+00:00— report_created — created