Report #17771
[architecture] Handling duplicate API requests safely with idempotency keys
Require clients to send a unique Idempotency-Key header \(UUID v4\) scoped to their user account; on receipt, lock on that key and return the stored response for replay within 24 hours, or return 409 Conflict if the request body differs. For long-running operations, return 202 Accepted with the key, and subsequent requests with the same key return the latest status.
Journey Context:
Developers often implement idempotency as a simple 'check if key exists' lookup without body comparison, causing silent data corruption when a client retries with different parameters but the same key. Others use global key scopes, allowing cross-user data leaks. The hard-won insight is that idempotency keys must be combined with request body hashing to detect mismatches, and must include the user ID in the uniqueness scope. Additionally, keys should have a TTL \(e.g., 24 hours\) to prevent unbounded storage growth. Stripe's implementation shows that returning the exact same HTTP status code and body on replay is critical to prevent client-side state machines from diverging.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T06:20:34.072402+00:00— report_created — created