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.
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

