0
0
Microservicessystem_design~12 mins

Outbox pattern for reliable events in Microservices - Architecture Diagram

Choose your learning style9 modes available
System Overview - Outbox pattern for reliable events

The Outbox pattern ensures reliable event delivery in microservices by storing events in a local database table (the outbox) as part of the same transaction that updates the business data. A separate process reads these events and publishes them to the message broker, guaranteeing no events are lost even if failures occur.

This pattern helps maintain data consistency and reliable communication between services.

Architecture Diagram
User
  |
  v
API Gateway
  |
  v
Service A (Business Logic + Outbox DB)
  |
  v
Outbox Poller
  |
  v
Message Broker
  |
  v
Service B (Event Consumer)
  |
  v
Service B Database
Components
User
user
Initiates requests to the system
API Gateway
api_gateway
Receives user requests and routes them to Service A
Service A (Business Logic + Outbox DB)
service
Processes business logic and writes events to the outbox table in the same transaction
Outbox Poller
service
Reads events from the outbox table and publishes them to the message broker
Message Broker
message_queue
Delivers events asynchronously to interested services
Service B (Event Consumer)
service
Consumes events from the message broker and updates its own database
Service B Database
database
Stores data updated by Service B based on received events
Request Flow - 7 Hops
UserAPI Gateway
API GatewayService A (Business Logic + Outbox DB)
Service A (Business Logic + Outbox DB)Service A (Business Logic + Outbox DB)
Outbox PollerService A (Business Logic + Outbox DB)
Outbox PollerMessage Broker
Message BrokerService B (Event Consumer)
Service B (Event Consumer)Service B Database
Failure Scenario
Component Fails:Message Broker
Impact:Events cannot be delivered to Service B, causing delays in event processing
Mitigation:Outbox Poller keeps events in the outbox table until broker is available; retries publishing events; message broker should be highly available with replication
Architecture Quiz - 3 Questions
Test your understanding
Why does Service A write events to the outbox table in the same transaction as business data updates?
ATo ensure events are not lost if the business update fails
BTo speed up event delivery to Service B
CTo avoid using a message broker
DTo reduce database storage
Design Principle
The Outbox pattern ensures reliable event delivery by combining business data updates and event recording in a single transaction, then asynchronously publishing events. This avoids lost or duplicated events and maintains data consistency across microservices.