liveBook · Manning

Saga orchestrator

As explained in Microservices Patterns, Second Edition

A saga orchestrator coordinates saga steps by invoking participants, maintaining saga state, and determining what to do based on their outcomes.

A saga orchestrator centralizes coordination of a system command that spans multiple services. It invokes saga participants, tracks state, and chooses the next operation from each outcome. If a forward transaction fails, it invokes compensating transactions for preceding steps. Steps typically run sequentially, although independent transactions can sometimes run concurrently. section 10.0 section 10.2

Creating an order

An orchestrator embedded in the Order Service creates an order, requests credit reservation from the Customer Service, requests inventory reservation from the Inventory Service, and approves the order. It performs local order operations directly and sends commands to the other services. If inventory is unavailable, it releases the reserved credit and rejects the order. section 10.2.1

Model the orchestrator as a state machine: states represent operations in progress and final outcomes, entry actions invoke participants, and transitions reflect operation outcomes. Persist the saga state durably, including application data needed by subsequent participants. This gives the execution an explicit, trackable form. section 10.2.2 section 10.2.6

Figure 10.13 The state machine for a saga orchestrator that invokes the participants using request/asynchronous-response. The state entry actions send command messages. The state transitions are triggered by reply messages.
orchestration async state machine

The state machine shows how command-sending entry actions and reply-triggered transitions coordinate an asynchronous saga. section 10.2.4

Choose how the orchestrator invokes participants:

  • Asynchronous messaging uses participant command channels and an orchestrator reply channel. Use request/asynchronous-response when the outcome is needed; one-way notifications can suit operations that return no data and cannot fail because of business-rule violations. section 10.2.4
  • Synchronous request/response can use HTTP. The orchestrator must retry transient communication failures; idempotent endpoints use a key to detect duplicate requests and return the original response. section 10.2.5

Place the orchestrator in a separate service or embed it in a participant. A separate service simplifies participants and reduces their design-time coupling, but adds architectural complexity and typically increases runtime coupling. Embedding reduces the service count and can permit an earlier response, but gives the entry-point service coordination responsibilities and can increase its design-time coupling. section 10.2.3

Orchestration makes a multistep saga easier to understand and keeps coordination out of participant business logic. It is more complex than event-driven choreography and requires an orchestration framework. Keep business decisions, such as checking available credit, in the responsible participant rather than building a smart orchestrator with dumb participants. For a simple saga, choreography may be the simpler choice. section 10.2.6 section 10.3

Prefer an existing orchestration framework over building the infrastructure yourself. Eventuate and Temporal are examples; an Eventuate-based Create Order Saga uses its framework for state management, messaging, and recovery. section 10.2.2 section 11.1.2

How Microservices Patterns, Second Edition covers it

How deep it goes
Explains state-machine modeling, persistent state, deployment choices, and asynchronous and synchronous invocation trade-offs.
Examples
Traces order creation through credit and inventory reservation, approval, and credit release on inventory failure.
What it assumes
Assumes familiarity with sagas, their design challenges, and coordination mechanisms before applying them to a detailed implementation.
What you can do after
Evaluate/understand orchestration choices and their effects on coupling, complexity, participant responsibilities, and failure handling.
How it connects
Connects saga orchestration to choreography, state machines, compensating transactions, asynchronous messaging, and idempotency.

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.