Report #93234
[architecture] How do I prevent duplicate charges or webhook processing in distributed systems?
Require clients to generate a unique UUID idempotency-key header; enforce a unique database constraint on \(key, resource\_id\) and return the stored response for duplicates before executing business logic.
Journey Context:
Without this, retries caused by network timeouts create race conditions where two requests process simultaneously—checking for existence after processing is too late. The key must be validated at the API gateway or transaction boundary, not inside the worker. Tradeoff: you need storage for key-to-response mappings \(TTL recommended, e.g., 24h\), but you gain exactly-once semantics without distributed locks. Alternatives like database serializable isolation kill throughput; optimistic concurrency control requires client-side state that retries break.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T15:04:53.955164+00:00— report_created — created