Transactional outbox
Saving an event to an outbox table in the same database transaction as the change itself, then publishing it to the broker separately.
You cannot write to the database and publish to a broker atomically: one can succeed while the other fails, and the system silently disagrees with itself. With an outbox, the state change and the event row commit together or not at all. A relay reads new rows (by polling or change data capture) and publishes them at least once, so consumers must ignore duplicates.
Related terms
- Inbox pattern (idempotent consumer): A consumer records the id of each processed message in the same transaction as its own change, and skips any id it has already seen.
- CDC (change data capture): Reading committed changes from a database’s own transaction log and streaming them as events to other systems.
- At-least-once delivery: A queue or broker guarantee that every message arrives, possibly more than once, so consumers must handle duplicates.
- CQRS (Command Query Responsibility Segregation): Splitting a system into a write side that changes data and a separate read side shaped for queries, often with its own store kept in sync by events.
- Dual-write problem: Writing one change to two systems, such as a database and a broker or an old and a new store, without a shared transaction, so they can drift apart.
- Domain event: A fact the business cares about, named in the past tense (“visit booked”), that other parts of the system can react to without being called directly.
