Report #104653
[architecture] How do I prevent duplicate processing of the same request in a distributed system?
Use idempotency keys: require clients to send a unique key \(e.g., UUID\) with each request. The server stores the key and its response for a timeout window \(e.g., 24h\). On duplicate key, return the stored response without re-processing. Use a database with strong consistency \(e.g., PostgreSQL unique constraint\) or a distributed lock to ensure atomic check-and-set.
Journey Context:
Common mistake: relying solely on database deduplication \(e.g., unique index on a business field\) which may not cover network retries. Idempotency keys decouple idempotence from business logic. Key must be generated by client, not server. Storage must handle concurrent requests: use conditional insert \(INSERT ... ON CONFLICT DO NOTHING\) or a Redis SETNX with expiry. Tradeoff: storage cost, key management, timeout window. Alternatives: using idempotent operations \(e.g., PUT instead of POST\) but not always possible. The pattern is widely used in payment APIs.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-09-20T20:05:01.705187+00:00— report_created — created