0
0
Microservicessystem_design~12 mins

Event sourcing pattern in Microservices - Architecture Diagram

Choose your learning style9 modes available
System Overview - Event sourcing pattern

The Event Sourcing pattern stores all changes to application state as a sequence of events. Instead of saving only the current state, the system records every state-changing event. This allows rebuilding the current state by replaying events, ensuring a full history and audit trail.

Key requirements include reliable event storage, event replay for state reconstruction, and eventual consistency between services.

Architecture Diagram
User
  |
  v
Load Balancer
  |
  v
API Gateway
  |
  v
Command Service ---> Event Store ---> Event Processor ---> Read Model Database
                          |                                   ^
                          v                                   |
                    Event Bus -------------------------------
Components
User
actor
Initiates commands to change system state
Load Balancer
load_balancer
Distributes incoming requests evenly to API Gateway instances
API Gateway
api_gateway
Receives client requests and routes them to appropriate services
Command Service
service
Handles commands, validates them, and creates events
Event Store
database
Stores all events in an append-only log for durability and replay
Event Bus
message_queue
Distributes events asynchronously to interested services
Event Processor
service
Consumes events from the bus and updates the read model
Read Model Database
database
Stores query-optimized views of current state for fast reads
Request Flow - 9 Hops
UserLoad Balancer
Load BalancerAPI Gateway
API GatewayCommand Service
Command ServiceEvent Store
Event StoreEvent Bus
Event BusEvent Processor
Event ProcessorRead Model Database
Command ServiceAPI Gateway
API GatewayUser
Failure Scenario
Component Fails:Event Store
Impact:New events cannot be saved, so state changes are lost and system cannot rebuild state from events.
Mitigation:Use replication and backups for Event Store. If failure occurs, switch to replica or restore from backup to resume event logging.
Architecture Quiz - 3 Questions
Test your understanding
Which component is responsible for storing all changes as events?
AEvent Store
BRead Model Database
CAPI Gateway
DEvent Processor
Design Principle
This architecture demonstrates the Event Sourcing pattern by storing all state changes as immutable events in an append-only log. It separates command handling from query models, enabling reliable state reconstruction and auditability. Asynchronous event processing ensures scalability and eventual consistency.