Report #50539
[architecture] How to reliably publish domain events to a message bus without 2PC or data loss
Use the Transactional Outbox pattern: write events to an 'outbox' table in the same database transaction as your business data changes, then use a separate 'relay' process to poll and publish those events to the message bus, marking them as sent only after acknowledgment.
Journey Context:
Direct 'publish-then-commit' risks data loss if the commit fails; 'commit-then-publish' risks events never being published if the broker is down. 2PC/XA transactions kill availability and performance. The outbox pattern accepts eventual consistency by leveraging the same ACID transaction for business data and events, ensuring at-least-once delivery. The relay must be idempotent or use tracking to avoid duplicates during retries. Common mistake is forgetting to handle the relay process failure scenario—treat the relay as a critical service, not a 'nice-to-have' sidecar.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T15:18:47.320088+00:00— report_created — created