When a system command spans multiple services, a saga must coordinate their transactions and handle failures. Orchestration centralizes that coordination in an orchestrator: it invokes a participant, evaluates the outcome, and decides which participant to invoke next. If a forward transaction fails, it invokes compensating transactions for preceding steps. section 10.0 section 10.2
The orchestrator can invoke participants synchronously or asynchronously, and can live in a separate service or be embedded in a participant. Steps often run sequentially, although independent transactions can sometimes run concurrently. If a request’s outcome is unknown, simply rejecting the overall operation can leave the system inconsistent; the coordination logic may need to send a compensating request. section 10.2 section 9.2.3
Creating an order
A six-step Create Order Saga involves four participants, with compensation for four steps. Its orchestrator is embedded in the Order Service and sends commands to participant channels; replies arrive on a reply channel. Order creation and updates are local operations. Eventuate Tram Saga supplies orchestration infrastructure, while the Transaction Outbox and Idempotent Consumer patterns support reliable message delivery and processing. section 11.1.2 section 11.4
Figure 11.1 Implementing the Create Order Saga using orchestration. The Order Service implements a saga orchestrator, which invokes the saga participants using asynchronous request/response.
The diagram shows the Order Service orchestrator invoking participants through asynchronous request/response. section 11.1.2
Choose the coordination approach by weighing clarity against complexity:
- Orchestration gives a saga a centralized definition and persistent, queryable state. Participants depend less on one another and can keep coordination logic out of their domain objects. section 10.2.6
- Orchestration adds framework complexity and can accumulate business logic that belongs in participants. Keep the orchestrator focused on coordination; for example, let the Customer Service perform its own credit check. section 10.2.6
- Choreography distributes sequencing through events and works well for simple sagas. As steps and participants multiply, its distributed flow can be harder to understand than a centralized orchestrator. section 10.3
