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
Pattern Description
In this particular saga pattern implementation (choreography) there is no central orchestrator to conduct the workflow, rather, the initial request is initiated by what is called a front controller, in this case it is the VDS service. After successfully completing their work, the services will begin invoking the other service(s) that come after them, all the way until the last service has been reached, which will then return the result. If however, an error was to occur, then each service must have built-in compensating logic, to send requests back along the chain to the front controller.
Pattern Characteristics | |
---|---|
Coupling | Since this pattern uses a choreographed approach but still uses synchronous communication, the coupling is reduced slight. It is slightly reduced because of the transactional requirement which must be distributed across the different services. |
Complexity | This pattern exhibits high level of complexity because of the built in compensating logic in each of the services involved in the workflow. This will most likely continue to increase as new services are added or removed. |
Responsiveness/Availability | Slightly increased because of the lack of orchestration, but would be diminished quite rapidly because of the built in compensating error correction logic. |
Scale/Elasticity | Scalability for this pattern is slightly increased because of the lack of bottlenecks as a result of orchestration. However this pattern’s implementation is synchronous and exhibits tight coupling, and if deployed in an environment which has high error rates, then the scalability is greatly diminished. |
Saga Pattern 3 - Synchronous / Eventual / Orchestration
Glossary
Term | Definition |
---|---|
Atomic | |
Bottlenecks | |
Elasticity | |
CDS | |
VRG | |
VDS | |
VRS | |
WMS | |
Sync |