Sagas are coordinated in two ways:
Through Orchestration - a target service (can be a standalone or a participant in the transaction) is designated as the coordinator of the steps/state to complete a set distributed transaction by invoking/emitting events to other services either asynchronously or synchronously.
Through Choreography - each service invokes/emits an event that prompts the next service in line to complete its transaction either asynchronously or synchronously.
Distributed transaction matrix | ||
---|---|---|
Communication | Consistency | Coordination |
Synchronous | Atomic | Orchestration |
Synchronous | Atomic | Choreography |
Synchronous | Eventual | Orchestration |
Synchronous | Eventual | Choreography |
Asynchronous | Atomic | Orchestration |
Asynchronous | Atomic | Choreography |
Asynchronous | Eventual | Orchestration |
Asynchronous | Eventual | Choreography |
Saga State Machine for scenarios
To better visualize the state transitions you can refer to the "Vessel Registry Controller Microservice: Saga Orchestrator" post to get more details. We will omit that section from this document as it is well documented there.
Saga Pattern 1 - Synchronous / Atomic / Orchestration
Pattern Description
An orchestrator in this case the VRG coordinates the workflow of the involved services. All communication in this workflow are synchronous. The transaction boundary specifies that the transactions will either all succeed or none will. If one of the services involved in this workflow, fails, the orchestrator issues compensating calls to the preceding services to undo the changes that were made, as shown in the “Transaction Failed Path” diagram (Red Lines).
Pattern Characteristics | |
---|---|
Coupling | This saga pattern implementation exhibits high degree of coupling. This pattern closely resembles the communication style of a monolithic application. |
Complexity | Low level of complexity are associated with implementing this pattern, because it reduces the chances of race conditions and deadlocks. |
Responsiveness/Availability | Due the coordination done by the orchestator and the synchronous communication it will exhibit bottlenecks, and reduced performance under high loads. There is also a high chance that this implementation will fail when the services the orchestrator coordinates during the workflow are in an unrecoverable error state. |
Scale/Elasticity | Due to the communication style and coordination, scaling this pattern will prove to be difficult. |
Saga Pattern 2 - Synchronous / Atomic / Choreography
Glossary
Term | Definition |
---|---|
Atomic | |
Bottlenecks | |
Elasticity | |
CDS | |
VRG | |
VDS | |
VRS | |
WMS | |
Sync |