Report #82116
[architecture] Ensuring message delivery to message bus without losing data during database commit
Implement Outbox Pattern: write events to an 'outbox' table in the same database transaction as business data changes; use a separate relay process to poll and publish committed events to the message bus, marking them as processed only after confirmed publish.
Journey Context:
Common anti-pattern: dual-write \(write to DB then send to Kafka\). If the process crashes between operations, you have inconsistent state \(data committed but event lost, or event sent but transaction rolled back\). Distributed transactions \(2PC/XA\) solve this but are operationally complex, blocking, and not supported by many modern stores \(e.g., MongoDB, Cassandra\). Outbox pattern provides 'eventual consistency' without 2PC. Critical implementation details: \(1\) Outbox table must be in same DB/transaction as business data; \(2\) Relay must handle 'at-least-once' delivery \(idempotent consumers downstream required\); \(3\) Relay must use polling or CDC \(Change Data Capture like Debezium\) to detect new events; \(4\) Processed events should be deleted or archived, not kept indefinitely. Alternatives: Change Data Capture \(Debezium\) directly on transaction log achieves same outcome without polling overhead but requires DB binlog access.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T20:25:27.093948+00:00— report_created — created