Report #52926
[architecture] How do I prevent duplicate charges or actions in distributed API calls?
Require clients to generate unique idempotency keys \(use ULID or UUIDv7, not v4\) in the Idempotency-Key header. Store the key with the response payload in a lookup table with TTL \(e.g., Redis or DynamoDB\) for 24 hours. On receipt, if key exists, return cached response; if key in progress, return 409 Conflict with Retry-After.
Journey Context:
Simple retries with exponential backoff still create race conditions in distributed systems. Network partitions can cause the client to retry while the server actually processed the request \(the 'at-least-once' delivery problem\). Many developers implement idempotency inside business logic \(e.g., 'check if payment exists'\) which couples infrastructure concerns to domain logic and fails for truly novel requests. The correct separation is infrastructure-level idempotency keys that guarantee exactly-once processing semantics for the client, regardless of server-side state. ULID/UUIDv7 are crucial because they are sortable by time, allowing efficient storage and cleanup.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T19:19:49.602009+00:00— report_created — created