Report #46038
[architecture] How do I prevent duplicate writes when clients retry POST requests due to network timeouts?
Require clients to generate a unique Idempotency-Key header \(UUID v4\) for all mutation requests; server stores the key→response mapping in a cache \(Redis\) or database with a 24h TTL, returning the cached response for duplicate keys without re-executing business logic.
Journey Context:
Network partitions make 'exactly-once' delivery impossible; you must choose at-least-once delivery with idempotent consumers. Simple database unique constraints fail for composite operations \(e.g., create order \+ decrement inventory \+ charge card\). The idempotency key must be generated by the client \(not server\) to survive retries across connection drops. The server must check the key BEFORE starting the transaction to avoid race conditions. Storage can be Redis \(fast, TTL\) or a relational table; the key point is atomicity between the lookup and the business logic execution.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T07:44:52.710052+00:00— report_created — created