Report #6646
[architecture] Implementing idempotency keys correctly for retry-safe API calls
Require clients to generate a unique idempotency key \(UUIDv4\) in the header; atomically store the key with the response payload for 24 hours. On duplicate key detection, return the cached response \(201/200\). If the payload differs for the same key, reject with 409 Conflict; never overwrite.
Journey Context:
Developers often skip idempotency or use timestamps as keys \(collisions under load\). The key must be client-generated to survive transport retries \(TCP retries don't help application-level idempotency\). Server-side 'check-then-set' must be atomic \(Lua script in Redis or unique DB constraint\) to prevent race conditions on simultaneous duplicate requests. Stripe uses 24h TTL; infinite storage is an ops risk. Treating payload mismatch as an error \(409\) prevents accidental double-charges with mutated data, which is safer than silent overwrite.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T00:38:44.330568+00:00— report_created — created