0
0
Microservicessystem_design~12 mins

Saga pattern for distributed transactions in Microservices - Architecture Diagram

Choose your learning style9 modes available
System Overview - Saga pattern for distributed transactions

The Saga pattern manages distributed transactions across multiple microservices without locking resources. It breaks a large transaction into smaller steps, each handled by a service, with compensating actions to undo changes if something fails. This ensures data consistency and reliability in complex systems.

Architecture Diagram
User
  |
  v
API Gateway
  |
  v
Saga Orchestrator
  |       |       |
  v       v       v
Service A  Service B  Service C
  |         |         |
  v         v         v
Database A Database B Database C
Components
User
actor
Initiates the distributed transaction request
API Gateway
gateway
Receives user requests and routes them to the Saga Orchestrator
Saga Orchestrator
orchestrator
Controls the sequence of service calls and manages compensations on failure
Service A
service
Executes first step of the transaction and updates Database A
Service B
service
Executes second step of the transaction and updates Database B
Service C
service
Executes final step of the transaction and updates Database C
Database A
database
Stores data for Service A
Database B
database
Stores data for Service B
Database C
database
Stores data for Service C
Request Flow - 13 Hops
UserAPI Gateway
API GatewaySaga Orchestrator
Saga OrchestratorService A
Service ADatabase A
Service ASaga Orchestrator
Saga OrchestratorService B
Service BDatabase B
Service BSaga Orchestrator
Saga OrchestratorService C
Service CDatabase C
Service CSaga Orchestrator
Saga OrchestratorAPI Gateway
API GatewayUser
Failure Scenario
Component Fails:Service B
Impact:Step 2 fails, transaction cannot complete; previous step (Service A) changes must be undone
Mitigation:Saga Orchestrator triggers compensating transaction on Service A to rollback step 1 changes, then reports failure to user
Architecture Quiz - 3 Questions
Test your understanding
Which component manages the sequence of distributed transaction steps and compensations?
AAPI Gateway
BSaga Orchestrator
CService A
DDatabase B
Design Principle
The Saga pattern breaks a large distributed transaction into smaller steps managed by an orchestrator. Each step updates its own database and confirms success. If any step fails, compensating actions undo previous changes, ensuring eventual consistency without locking resources.