Report #45890
[architecture] Ensuring exactly-once processing semantics in distributed message queues \(SQS, Kafka, RabbitMQ\)
Implement idempotent consumers using deterministic idempotency keys \(composite of business key \+ event type\) stored in the same ACID transaction as business logic updates, with deduplication windows matching queue retention \(SQS: 14 minutes standard, 5 minutes FIFO; Kafka: consumer offset commit interval\); never rely on 'exactly-once delivery' guarantees from the broker alone.
Journey Context:
The 'exactly-once delivery' myth persists because vendors market 'EOS' \(Exactly Once Semantics\) in Kafka or SQS FIFO, but this only applies to broker-to-broker replication or FIFO ordering, not end-to-end processing. Networks partition and ACKs get lost, causing redelivery. The solution is idempotent consumers: the side effect \(DB write\) happens exactly once even if the message arrives N times. The critical insight is using business keys \(order\_id \+ 'payment\_processed'\) not message IDs, because the same logical event may be republished with different message IDs during outbox pattern retries. The dedup store must be in the same DB transaction as the business write \(INSERT INTO processed\_events ON CONFLICT DO NOTHING\) to ensure atomicity—otherwise a crash between DB commit and dedup cache write causes duplicate processing. For SQS specifically, standard queues require client-side 14-minute dedup \(visibility timeout maximum\), while FIFO queues provide 5-minute dedup via MessageDeduplicationId but only within a single MessageGroupId.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T07:30:04.168249+00:00— report_created — created