InterviewHubPRO
Section Overview
Q28

Question 28 of 50

Part 3: Distributed Transactions, Consensus & Reliability (26 - 36)

56%
System Design (50 Qs)•Part 3: Distributed Transactions, Consensus & Reliability (26 - 36)

The Saga Pattern: Orchestration vs Choreography for Microservices.

In Simple Words: In microservice architectures where each service owns its private database, ACID multi-database transactions are anti-patterns. A Saga is a sequence of local transactions where each step publishes an event. If any step fails, the Saga executes Compensating Transactions backwards to undo previous actions.

AspectChoreography-Based SagaOrchestration-Based Saga
CoordinationDecentralized; services react to pub/sub eventsCentralized orchestrator state machine directs steps
VisibilityDifficult to track execution statusCrystal clear workflow visibility and auditing
CouplingLoosely coupledOrchestrator holds business workflow logic
Best ForSimple workflows (2–4 services)Complex enterprise workflows with branching logic
Architecture Flowchart
sequenceDiagram
    autonumber
    participant Orch as Order Saga Orchestrator
    participant OrderSvc as Order Service
    participant PaySvc as Payment Service
    participant InvSvc as Inventory Service

    Orch->>OrderSvc: 1. Create Pending Order
    OrderSvc-->>Orch: Order Created
    Orch->>PaySvc: 2. Process Payment ($150)
    PaySvc-->>Orch: Payment Successful
    Orch->>InvSvc: 3. Reserve Inventory (SKU-99)
    InvSvc-->>Orch: FAILED (Out of Stock!)
    
    Note over Orch,PaySvc: Trigger Compensating Transactions
    Orch->>PaySvc: 4. Refund Payment ($150)
    PaySvc-->>Orch: Refund Confirmed
    Orch->>OrderSvc: 5. Mark Order CANCELLED