A saga participant is a service or component that performs one or more local transactions in a saga. Participants let a system command span services without relying on a classic distributed transaction. Each forward step can lead to another participant; if a step fails, compensating transactions undo preceding steps in reverse order. section 10.0 section 9.2.3
Participants need data from the original request and sometimes from earlier steps. Coordination must carry that data to the participant that needs it and use each transaction’s outcome to determine what happens next. section 9.2.3 section 10.0
The coordination mechanism determines how participants interact:
- Choreography distributes sequencing among participants. A step publishes an event containing its outcome and data for the next step; a failure event triggers compensation. This is simple for small sagas, but flows with many steps or participants can be difficult to understand. section 10.1 section 10.3
- Orchestration centralizes sequencing in an orchestrator that invokes participant operations and selects the next step from their outcomes. It is more complicated and requires an orchestration framework, but makes multistep flows easier to understand. section 10.0 section 10.3
Creating an order
An orchestrator embedded in Order Service creates an order, sends a credit reservation command to Customer Service, and then sends an inventory reservation command to Inventory Service. After successful replies, it approves the order locally. If inventory is unavailable, it instructs Customer Service to release credit and rejects the order. The credit reservation needs the customer ID from the request and the order total calculated by Order Service. section 10.2.1 section 9.2.3
An orchestrator can live in a separate service or be embedded in a participant. A separate service simplifies participants and reduces their design-time coupling, but adds architectural complexity and can increase runtime coupling. Embedding it reduces the number of services and may permit an earlier response, but gives the entry-point participant coordination responsibilities and dependencies on other participants. section 10.2.3
For asynchronous orchestration, participants can handle commands by invoking business logic and sending replies. Participant proxies can encapsulate commands and isolate the orchestrator from messaging details; reliable delivery and processing also require attention to the transaction outbox and idempotent consumer patterns. section 11.4 section 11.1.2
