Report #86855
[architecture] Achieving exactly-once semantics with at-least-once brokers
Design consumers to be idempotent \(processing the same message multiple times produces the same state\) using natural business keys or store processed message IDs in the application database within the same transaction as the business update; avoid distributed transactions or relying solely on manual ACKs for critical operations.
Journey Context:
Message brokers \(Kafka, SQS, NATS\) guarantee at-least-once delivery because network partitions or consumer crashes prevent ACKs from reaching the broker, causing redeliveries. Attempting exactly-once via distributed two-phase commits \(XA transactions\) adds massive latency and operational fragility. The pragmatic solution is the 'idempotent consumer' pattern: either design operations to be naturally idempotent \(e.g., 'set status to processed' rather than 'increment counter'\) or track processed message IDs in the same database transaction as the business update. This provides 'effectively exactly-once' semantics without coordination overhead. Tradeoff: idempotent design constrains data models \(favors upserts over increments\) and requires storage for deduplication keys.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T04:22:27.462767+00:00— report_created — created