QamoosTech
Architecture & DesignPatternsIntermediate

Transactional Outbox

Pronunciationtran-ZAK-shun-ul OWT-box

Definition

The transactional outbox pattern saves an event in an "outbox" table in the same database transaction as the business change, and a separate process later publishes it to the message broker. It avoids writing to two systems at once.

Where you hear it

In microservice and event-driven designs, Kafka or RabbitMQ publishing, and "the DB saved but the event was lost" bugs.

Examples

  • We insert the order and its OrderCreated event in one transaction.
  • A relay reads the outbox table and publishes each row.
  • The order and its event are written in one transaction, so no event is lost.

Common mistake

Saving to the database and then publishing to the queue as two steps. A crash between them loses the event.

Don't confuse with

A dead-letter queue, which holds messages that failed to process. The outbox is about reliably sending them in the first place.

Say it at work

  • In a meeting or chatUse the outbox pattern; never dual-write.
  • In an email or ticketConsumers must handle duplicates because delivery is at-least-once.