Choreography-Based Sagas
What You'll Learn
You'll discover how services coordinate distributed transactions through event-driven autonomy rather than central control.
The Core Idea
In a choreography-based saga, there's no central coordinator telling services what to do. Instead, each service listens for domain events, performs its local transaction, and publishes new events that other services react to. It's like a relay race where runners automatically know when to start based on watching the previous runner pass the baton—no race official needed at each handoff.
When an order service creates an order, it publishes an "OrderCreated" event. The payment service listens for this event, processes payment, and publishes either "PaymentSucceeded" or "PaymentFailed." The inventory service listens for "PaymentSucceeded" and reserves items, publishing its own outcome event. Each service independently decides what to do based on what it observes.
How It Works
Each service in the saga:
- Subscribes to relevant events from other services
- Performs its local transaction when triggered
- Publishes outcome events that others can react to
- Implements compensating actions if it receives failure events
If payment succeeds but inventory reservation fails, the inventory service publishes "InventoryReservationFailed." The payment service, listening for this, triggers its compensating transaction to refund the payment.
Advantages and Challenges
Choreography eliminates the single coordinator bottleneck from orchestration patterns. Services are loosely coupled—they only know about events, not about each other directly. However, understanding the complete saga flow requires tracing events across multiple services, and there's no single place that defines the entire business process.
Key Takeaway: Choreography-based sagas coordinate distributed transactions through autonomous services reacting to domain events, enabling loose coupling but requiring careful event design to maintain system-wide understanding.