📡 You're offline — showing cached content
New version available!
Quick Access
Tutorials Microservices The Saga Pattern

The Saga Pattern

6 min read Quiz at the end
Sagas manage distributed transactions with compensating rollback actions — choreography or orchestration.

The Saga Pattern

Sagas manage distributed transactions across services using local transactions and compensating rollback actions.

# Order saga steps
# 1. order-service creates order (PENDING)
# 2. inventory-service reserves stock
# 3. payment-service charges card
# 4. order-service marks CONFIRMED

# If step 3 fails -- compensate:
#   inventory-service releases reserved stock
#   order-service cancels order

# Choreography (event-driven)
order-svc  --OrderCreated--> Kafka
inventory  --listens--> reserves --StockReserved--> Kafka
payment    --listens--> charges  --PaymentDone-->   Kafka
order-svc  --listens--> confirms

# Orchestration (central coordinator)
saga-coordinator:
  1. reserve()  -- fail: stop
  2. charge()   -- fail: release()
  3. confirm()  -- done
Topic Quiz · 2 questions

Test your understanding before moving on

1. In a Saga, what is a compensating action?
💡 Compensating actions undo completed steps — e.g. releasing reserved stock when payment fails.
2. What is the difference between choreography and orchestration in Sagas?
💡 Choreography uses events (decoupled, harder to trace); Orchestration uses a coordinator (clear flow, SPOF risk).