A choreography-based saga coordinates a system command across services without a central orchestrator. Participants distribute sequencing and decisions by publishing events: each forward or compensating transaction emits an event that triggers the next step. section 10.0 section 10.1
The first participant handles the command, updates its database, and publishes an event. An event handler in the next participant executes its step and publishes another event. If a forward step fails, a failure event triggers compensation; subsequent events trigger any remaining compensations in reverse order. section 10.1 section 10.3
Creating an order
The Order Service handles POST /orders, creates an order, and publishes OrderCreated. The Customer Service consumes that event and attempts to reserve credit. Credit Reserved triggers order approval; Customer Lookup Failed or Credit Limit Exceeded triggers rejection. section 10.1.1
Table 10.1 The choreography-based version of the Create Order Saga.
|
Choreography-based Saga canvas |
||||
|
System command: |
createOrder(customerId, productId) |
|||
|
Initiating service: |
Order Service |
|||
|
Step |
Triggering event |
Participant Service |
Command |
Published event(s) |
|
1 |
- |
Order Service |
createOrder() |
|
|
2 |
Order Created |
Customer Service |
reserveCredit() |
|
|
3a |
Credit Reserved |
Order Service |
approveOrder() |
|
|
3b |
Customer Lookup Failed |
Order Service |
rejectOrder() |
|
|
3c |
Credit Limit Exceeded |
Order Service |
rejectOrder() |
|
The saga canvas maps each triggering event to its participant, command, and possible published events. section 10.1.1
Design the event flow around these responsibilities:
- Events communicate operation outcomes and carry the data later participants need. For example, OrderCreated carries the customer and order identifiers to the Customer Service. section 10.1.2
- Channels transport events, publishers emit them, and handlers consume them to advance the saga. Channel design affects coupling, scalability, and evolution; publishing also raises reliability and ordering concerns. section 10.1.2
- Compensation must be explicit: sagas do not provide automatic rollback, and their lack of isolation requires care to prevent inconsistencies. section 9.2.4
Choreography is often straightforward for a simple saga and provides loose runtime coupling through asynchronous messages. It becomes harder to understand as participants and interactions multiply, and can introduce design-time coupling or cyclic dependencies. An orchestrator centralizes sequencing and can make a complex saga easier to understand, but adds coordination infrastructure. Prefer choreography when the event flow remains simple enough to follow; consider orchestration as complexity grows. section 10.1.4 section 10.3
