This article was originally published on bmf-tech.com.
Overview
Notes on what I researched about the Saga pattern.
What is the Saga Pattern
- In microservices, distributed transactions (such as 2phase commit) are not recommended
- The Saga pattern is used to ensure consistency while avoiding distributed transactions
- Avoids long-term locks and uses eventual consistency
- Compensating transactions
- Operations that cancel a series of transactions
- The Saga pattern prohibits simple rollbacks
- Not a pattern unique to microservices, it was also used in SOA
- Implementation patterns
- Choreography
- Each service progresses the transaction with its own responsibility
- Avoids SPOF, but makes overall testing difficult
- Orchestration
- A central service is prepared to instruct each service to progress the transaction
- Prone to SPOF, but makes overall testing easier
- Software Architecture: The Hard Parts introduces eight types of Saga patterns
Other Patterns
Another pattern to maintain consistency in microservices, similar to the Saga pattern, is the TCC (Try-Confirm/Cancel) pattern, which also uses eventual consistency.
The TCC pattern is similar to 2phase commit, but in the TCC pattern, each service has three steps: preparation, confirmation, and cancellation of the transaction.
The TCC pattern does not perform rollbacks like compensating transactions, but ensures consistency by not performing processes that cause inconsistencies.
References
- www.cs.cornell.edu - SAGAS
- microservices.io - Pattern: Saga
- qiita.com - The Dangers of Distributed Transactions When Migrating to Microservices
- qiita.com - Designing Transaction Management in Microservices (Preliminary Knowledge)
- zenn.dev - Implementing the Saga Pattern with AWS (Choreography Edition)
- learn.microsoft.com - Saga Distributed Transaction Pattern
- docs.aws.amazon.com - Saga Pattern
- wakatchi.dev - Summarizing Microservices Transactions with TCC and Saga Patterns
- eikatou.net - Learning the Distributed Transaction Saga Pattern
- techblog.raksul.com - Verification Using the Saga Pattern in Microservices
- www.techscore.com - Transactions in Microservices [Saga]
- www.12-technology.com - [SAGA Pattern] Advantages and Disadvantages of Choreography and Orchestration
- cloud.google.com - Implementing the Saga Pattern with Workflows
- medium.com - Microservices Saga Pattern on GCP
- www.oracle.com - The Reality of Transaction Management in Microservices Architecture
- speakerdeck.com - Suddenly Realizing It's a Saga Pattern!? Operating a Serverless Backend with a Small Team
- engineering.mercari.com - Distributed Transaction Management in Mercari Coin Payment Infrastructure
Top comments (0)