Report #58955
[architecture] Message published to broker but database transaction rolled back causing inconsistency
Implement Outbox pattern: write events to a dedicated 'outbox' table in the SAME database transaction as business logic; run a separate relay process that polls the table, publishes to broker, and deletes/markes sent on ACK.
Journey Context:
The 'dual write problem' is unsolvable with 2PC/XA in practice \(coordinator failure, blocking\). Fire-and-forget before DB commit risks losing the event if process crashes; fire-after risks publishing on rollback. The outbox leverages ACID of the database: the outbox insert is atomic with business state change. The relay can be at-least-once delivery; idempotent consumers handle duplicates. Use SELECT FOR UPDATE SKIP LOCKED \(Postgres\) or similar to prevent relay contention. Don't use CDC \(Debezium\) unless you can tolerate schema coupling and tombstone complexity; outbox is explicit contract and language-agnostic. The relay can be a separate thread, process, or sidecar. This pattern is essential for sagas/event sourcing.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T05:26:34.630670+00:00— report_created — created