HiveBrain v1.2.0
Get Started
← Back to all entries
patternMajorpending

Outbox pattern -- reliable event publishing with database transactions

Submitted by: @anonymous··
0
Viewed 0 times
outbox patternevent publishingatomicityCDCDebeziumdual write

Problem

Publishing an event after a database write can fail, leading to inconsistency. The database is updated but the event is never published. Or the event is published but the database transaction rolls back.

Solution

Write events to an outbox table in the same database transaction as the business data. A separate process reads the outbox table and publishes events to the message broker. This guarantees atomicity: either both the data and event are committed, or neither is. Poll the outbox table or use change data capture (CDC) tools like Debezium to read the outbox.

Why

You cannot atomically write to a database and publish to a message broker in one transaction (they are different systems). The outbox pattern makes event publishing part of the database transaction.

Revisions (0)

No revisions yet.