Report #66352
[architecture] Designing idempotent API endpoints that fail on concurrent duplicate requests
Store idempotency key with 'processing' state before business logic; reject duplicates only if status is 'completed' or 'processing' with timeout check, not on mere existence.
Journey Context:
The common anti-pattern is checking if the key exists in a lookup table before processing. This fails under concurrent retries: Request A starts processing, Request B arrives before A finishes, sees no completed record, and starts double-processing. The correct state machine is: RECEIVED -> PROCESSING \(locked\) -> COMPLETED/FAILED. The lock must have a TTL to handle crashes. This pattern requires row-level locking or atomic compare-and-swap operations on the state column, distinct from simple 'insert ignore' idempotency.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T17:50:49.019870+00:00— report_created — created