Understanding the SAGA Pattern in a simple AWSway
In the AWS Prescriptive Guidance Enabling data persistence in microservices, AWS describes the SAG pattern as follows:
“The saga pattern is a failure management pattern that helps establish consistency in distributed applications, and coordinates transactions between multiple microservices to maintain data consistency. A microservice publishes an event for every transaction, and the next transaction is initiated based on the event’s outcome. It can take two different paths, depending on the success or failure of the transactions.
The following illustration shows how the saga pattern implements an order processing system by using AWS Step Functions. Each step (for example, “ProcessPayment”) also has separate steps to handle the success (for example, “UpdateCustomerAccount”) or failure (for example, “SetOrderFailure”) of the process.”
I have understood it in a simpler way, using an analogy.
Think of a group of musicians in an orchestra:
Image courtesy of https://www.freepik.com/
Each playing a different instrumenta and to create a harmonious performance, the musicians need to play in sync, following the conductor’s guidance. The conductor manages the tempo, dynamics, and coordination between the musicians to ensure a consistent and cohesive performance.
In this analogy, the orchestra represents the microservices in our business application, and each musician represents a separate service. The conductor represents AWS Step Functions, which maintains data consistency across these microservices during distributed transactions.
A successful musical performance relies on each musician playing their part correctly and in harmony with the others. Similarly, in a distributed transaction, each microservice must execute its part of the transaction accurately and in coordination with the others. If an issue arises during the performance, such as a musician playing the wrong note, the conductor (Step Functions) can adapt by signaling the musician to correct the error, thereby maintaining the harmony and consistency of the performance.
Each musician’s part in the performance represents a step in the SAGA pattern, with the conductor ensuring that all steps are completed in the proper sequence and in harmony with one another. If a step encounters a problem, the conductor knows how to handle the issue and adapt to keep the entire performance consistent and successful.
If you want to learn more about AWS Step Functions please visit the following microsite: Getting Started with AWS Step Functions