Report #59529
[architecture] How to implement exactly-once processing for webhooks and API calls
Use client-generated UUIDv7 idempotency keys with a server-side TTL-backed unique constraint \(e.g., Redis SET key NX EX or DB unique index\), not just 'check-then-insert' logic
Journey Context:
Developers often implement idempotency as 'SELECT to check if processed, then INSERT' which fails under race conditions between the check and write. The window creates duplicates under concurrent load. The fix is atomic conditional writes: either use a unique database constraint on the idempotency key \(with a TTL column to allow cleanup\) or Redis SET with NX \(not-set-if-exists\) and EX \(expiry\). Use UUIDv7 instead of UUIDv4 because time-ordered keys preserve database index locality and insert performance, avoiding random page splits. This pattern is critical for payment webhooks and retry storms.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T06:24:31.981407+00:00— report_created — created