.NET Architecture & System Design Interview Question #91

What is the Outbox Pattern?

Transactions, CQRS, Event Sourcing & Distributed Consistency Mid-Level Intermediate

Quick Interview Answer

The Outbox Pattern helps keep a local database update and the intent to publish a message consistent without requiring a distributed transaction. The application writes business data and an outbox record in the same local transaction.

Detailed Explanation

The Outbox Pattern helps keep a local database update and the intent to publish a message consistent without requiring a distributed transaction. The application writes business data and an outbox record in the same local transaction.

A separate publisher reads committed outbox records and sends them to the message broker. Publishing can occur more than once, so consumers should still handle duplicates safely.

Code Example

Database transaction:
  Save Order
  Save OutboxMessage
  COMMIT

Publisher:
Outbox -> Message Broker