C
CIOPages
Back to Glossary

Architecture Patterns

Outbox Pattern

The Outbox Pattern is a reliability pattern that ensures atomicity between database updates and message publishing by writing outgoing messages to an 'outbox' table within the same database transaction as the business data change, then using a separate process to reliably publish these messages to the message broker.

Context for Technology Leaders

For CIOs, the Outbox Pattern solves a critical reliability challenge in event-driven microservices—ensuring that business data changes and corresponding event notifications are never out of sync. Enterprise architects mandate this pattern for services that must reliably publish events after database changes.

Key Principles

  • 1Atomic Write: The business data change and the outgoing message are written in the same database transaction, guaranteeing that either both are committed or neither is.
  • 2Reliable Publishing: A separate publisher process reads the outbox table and publishes messages to the message broker, retrying failures until successful delivery.
  • 3Eventual Delivery: Messages are guaranteed to be published eventually (as long as the publisher process runs), though there may be a brief delay between the data change and message publication.
  • 4Ordering Preservation: Messages in the outbox table maintain insertion order, enabling ordered message delivery when sequence matters.

Strategic Implications for CIOs

Enterprise architects should implement the Outbox Pattern for any service that needs to reliably publish events after database changes, particularly in event-driven and CQRS architectures.

Common Misconception

A common misconception is that publishing a message within a database transaction callback achieves the same reliability. If the application crashes after the database commit but before the message is published, the message is lost. The Outbox Pattern prevents this by making the message part of the database transaction itself.

Related Terms

Event-Driven ArchitectureCQRSSaga PatternMessage ReliabilityChange Data Capture