liveBook · Manning

Choreography-based saga

As explained in Microservices Patterns, Second Edition

Linear choreography is a saga coordination pattern in which events trigger saga participants sequentially.

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()

  • OrderCreated(customerId, orderId, orderTotal)

2

Order Created

Customer Service

reserveCredit()

  • Credit Reserved
  • Customer Lookup Failed
  • Credit Limit Exceeded

3a

Credit Reserved

Order Service

approveOrder()

  • Order Approved

3b

Customer Lookup Failed

Order Service

rejectOrder()

  • Order Rejected

3c

Credit Limit Exceeded

Order Service

rejectOrder()

  • Order Rejected

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

How Microservices Patterns, Second Edition covers it

How deep it goes
Details event flow, compensation, design elements, and coordination trade-offs.
Examples
Illustrates order creation, credit reservation, approval, and rejection across two services.
What you can do after
Evaluate choreography against orchestration for sagas of differing complexity.
How it connects
Connects sagas to publish/subscribe, compensating transactions, orchestration, and runtime coupling.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Microservices Patterns, Second Edition. The section links point to the parts of the book it draws on.