Report #57486
[architecture] Handling duplicate API requests safely without database unique constraints
Require clients to send a unique Idempotency-Key header \(UUID\); server stores a mapping of key→response with a 24-hour TTL, returning the cached response for duplicate keys without re-executing business logic.
Journey Context:
Developers often try to enforce idempotency via database unique constraints on natural keys like order\_id, but this fails for 'create' operations where the ID is generated by the server, and it couples infrastructure concerns to schema design. Others store idempotency keys indefinitely, causing unbounded table growth. The correct approach treats idempotency as a short-lived deduplication layer \(24h covers most retry windows\) that gates the actual transaction. This prevents the 'thundering herd' issue where retries arrive before the first request completes—by returning the in-flight status or queuing the second request rather than executing duplicate business logic. This decouples from domain logic and allows automatic key expiration to manage storage.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T02:58:47.488121+00:00— report_created — created