liveBook · Manning

Outbox table

As explained in Microservices Patterns, Second Edition

An outbox table is a persistent table that stores messages to be delivered reliably as part of an application's transaction.

An outbox table is a temporary message queue stored in a service’s database. It addresses the problem of atomically updating business data and publishing a message when distributed transactions are unsuitable or unavailable. section 8.3.8

Within the same local database transaction that changes business data, the service inserts the message into the outbox. A MessageRelay later reads the table and publishes messages to a broker. This keeps the data change and the message record atomic. section 8.3.8

Figure 8.17 A service reliably publishes a message by inserting it into an OUTBOX table as part of the transaction that updates the database. The Message Relay reads the OUTBOX table and publishes the messages to a message broker.
ReliablePublication

The diagram shows the business-data transaction writing to the outbox and the relay publishing its messages to a broker. section 8.3.8

Storage and relay choices shape the implementation:

  • With a relational database, a relay can periodically query the outbox for unpublished messages; mining the database transaction log is another publishing approach. section 8.3.8
  • Some NoSQL databases can store pending messages as a list on each business-entity record. Finding entities with pending messages efficiently is a challenge. section 8.3.8

Asynchronous order validation

An Order Service can create an order in PENDING state, insert messages into its outbox, and return an order ID without waiting for other services. It then exchanges messages with Consumer and Restaurant services to validate the order. section 8.3.9

How Microservices Patterns, Second Edition covers it

How deep it goes
Explains local transaction semantics and relay choices, while identifying efficient discovery of pending NoSQL messages as a challenge.
Examples
Uses an order service that stores a pending order and validates it asynchronously through consumer and restaurant services.
What you can do after
Build it from scratch by inserting messages in the business-data transaction and relaying them to a broker.
How it connects
Connects database transactions, message brokers, message relays, polling publishers, transaction-log mining, and asynchronous messaging.

Also explained in

Compare how 2 books explain outbox table →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Microservices Patterns, Second Edition. The section links point to the parts of the book it draws on.