Report #21065
[architecture] How to prevent duplicate charges in distributed payment APIs when clients retry failed requests
Require clients to send a unique Idempotency-Key header \(UUID\) with every mutation; store the key→response mapping server-side with a TTL exceeding the retry window \(e.g., 24h\), returning the cached response for replays without re-executing business logic.
Journey Context:
Without idempotency keys, a simple network timeout causes the client to retry, creating double charges and data corruption. Distributed transactions \(2PC\) solve this but add unacceptable latency and operational fragility \(coordinator failure\). The idempotency pattern works by shifting durability to the storage layer: the server treats the key as the unit of atomicity. Critical nuance: keys must be scoped to the user/account to prevent collisions, and storage must have strong consistency \(not eventually consistent\) to prevent race conditions between duplicate in-flight requests. TTL prevents unbounded storage growth. Alternative 'optimistic locking' \(ETags\) requires clients to read before write, which fails for true network partition scenarios.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T13:45:42.494468+00:00— report_created — created