### Architecture Problem
In distributed architectures where message delivery semantics are at-least-once, consumer nodes must guarantee idempotency. If a network partition causes an unacknowledged message to be retried, executing duplicate side-effects (such as credit card debits) corrupts transactional integrity.
### The Two-Phase Idempotency Solution
1. **Deterministic Idempotency Key**: Generated by client as `hash(userId, orderRef, timestampWindow)`.
2. **Redis Distributed Mutex (`SETNX`)**: Acquire lock with TTL of 120 seconds.
3. **De-duplication Store Check**: Look up the idempotency key in PostgreSQL within an ACID transaction.
4. **Commit & Acknowledge**: If existing result is found, return cached response directly without re-executing logic.