Report #80385
[architecture] Implementing idempotent payments or webhooks without double-charging or duplicate side effects
Require clients to send a unique Idempotency-Key header \(UUID v4\); store the key and the full response body in a transactional cache \(Redis or DB\) with a 24-hour TTL. Before executing business logic, check for the key; if present, return the stored response with HTTP 200 \(not 409\) to satisfy the client's need for the original result \(e.g., generated ID\).
Journey Context:
Developers often rely on database unique constraints to prevent duplicates, but this fails when a request is in-flight and the client retries due to a network timeout; the first request hasn't committed yet. Simply returning 409 Conflict on retry is wrong because the client needs the success response body \(e.g., the payment ID\) to reconcile its state. The idempotency cache must be updated in the same transaction as the business logic commit to avoid race conditions between the check and the write. Storing the full response body, not just a flag, is essential for satisfying idempotent retries.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T17:31:50.397453+00:00— report_created — created