SlideShare ist ein Scribd-Unternehmen logo
1 von 16
Saga Pattern
By Alexandr Prygun
Saga Pattern
Play
hys-enterprise.com
HYS Enterprise is a Dutch software
development company with more than
200 talented engineers from all over
the world hys-enterprise.com
UkraineNetherlands
My experience
5+ years experience .NET Developer / Team Lead in HYS Enterprise
Saga pattern
Monolith App
Saga Pattern
API Application Database
One call One transactionIncoming call
Saga Patterm
API
Gateway
Application 1 Database 1
Application 2 Database 2
Application 3 Database 3
Incoming call
SOA/Microservices App
Saga Pattern
2PC: Prepare Phase
API
Gateway
Application 1 Database 1
Application 2 Database 2
Application 3 Database 3
Incoming call
Propose
Vote
Propose
Vote
Propose
Vote
Saga Pattern
2PC: Commit Phase
API
Gateway
Application 1 Database 1
Application 2 Database 2
Application 3 Database 3
Incoming call
Commit/Abort
Done
Commit/Abort
Done
Commit/Abort
Done
Saga Pattern
2PC: Disadvantages
- Data stays locked until commit or abort command
- There is no mechanism to rollback other transactions in case one service fails
- Others have to wait until the slowest resource finish its confirmation.
- Bad scaling
Saga Pattern
Sagas History
Long Live Transactions
Hector Garcia-Molina, Kenneth Salem,
Princeton University, 1987
Saga Pattern
What is Saga?
- Saga is long-lived transaction
- Saga is collection of sub-transactions
Saga Pattern
Saga orchestrator
Hotel
Booking
Service
Database 1
Rent Car
Service Database 2
Flight Tickets
Service Database 3
Book Trip Start saga
Start book hotel
End book hotel
Start book car
End book car
Start book tickets
End book tickets
End saga
Saga Pattern
Saga choreography
Hotel
Booking
Service
Database 1
Rent Car
Service Database 2
Flight Tickets
Service Database 3
Book Trip Start saga
Hotel is booked
Car is booked
End saga
Tickets are booked
Saga Pattern
Unsuccessful Saga
Start saga
1. Start book hotel
2. End book hotel
3. Start book car
4. End book car
5. Start book flights
6. Flights booking fail
Abort saga
7. Start cancel car
8. End cancel car
9. Start cancel hotel
10. End cancel hotel
End saga
Commit steps
Rollback steps
Saga Pattern
Saga pros and cons
Main advantage is that it helps maintain data consistency across
multiple services without tight coupling.
Main disadvantage is the complexity from a programming point
of view. Compensating transaction should be designed.
Saga Pattern
Saga tips
- A unique distributed transaction ID should be created for each saga and it
should be present in each related command or event
- Saga commands should be idempotent
- All components should implement compensate commands handlers
- Compensate commands should be idempotent as well
- Avoid synchronous operations
Thank you
For your attention!
Any Questions?
Event Name

Weitere ähnliche Inhalte

Was ist angesagt?

Was ist angesagt? (20)

Simplifying Distributed Transactions with Sagas in Kafka (Stephen Zoio, Simpl...
Simplifying Distributed Transactions with Sagas in Kafka (Stephen Zoio, Simpl...Simplifying Distributed Transactions with Sagas in Kafka (Stephen Zoio, Simpl...
Simplifying Distributed Transactions with Sagas in Kafka (Stephen Zoio, Simpl...
 
Event-sourced systems with Kafka, Clojure, and Jackdaw
Event-sourced systems with Kafka, Clojure, and JackdawEvent-sourced systems with Kafka, Clojure, and Jackdaw
Event-sourced systems with Kafka, Clojure, and Jackdaw
 
Introduction to GraphQL
Introduction to GraphQLIntroduction to GraphQL
Introduction to GraphQL
 
Architecture Patterns for Multi-Region Active-Active Applications (ARC209-R2)...
Architecture Patterns for Multi-Region Active-Active Applications (ARC209-R2)...Architecture Patterns for Multi-Region Active-Active Applications (ARC209-R2)...
Architecture Patterns for Multi-Region Active-Active Applications (ARC209-R2)...
 
Collaborative Applications at Scale with RSocket
Collaborative Applications at Scale with RSocketCollaborative Applications at Scale with RSocket
Collaborative Applications at Scale with RSocket
 
Building resilient scheduling in distributed systems with Spring
Building resilient scheduling in distributed systems with SpringBuilding resilient scheduling in distributed systems with Spring
Building resilient scheduling in distributed systems with Spring
 
Disaster Recovery for Multi-Region Apache Kafka Ecosystems at Uber
Disaster Recovery for Multi-Region Apache Kafka Ecosystems at UberDisaster Recovery for Multi-Region Apache Kafka Ecosystems at Uber
Disaster Recovery for Multi-Region Apache Kafka Ecosystems at Uber
 
What's New for GitLab CI/CD February 2020
What's New for GitLab CI/CD February 2020What's New for GitLab CI/CD February 2020
What's New for GitLab CI/CD February 2020
 
Using Kafka: Anatomy of the Flowable event registry
Using Kafka: Anatomy of the Flowable event registryUsing Kafka: Anatomy of the Flowable event registry
Using Kafka: Anatomy of the Flowable event registry
 
Hashicorp Vault Open Source vs Enterprise
Hashicorp Vault Open Source vs EnterpriseHashicorp Vault Open Source vs Enterprise
Hashicorp Vault Open Source vs Enterprise
 
Kubernetes GitOps featuring GitHub, Kustomize and ArgoCD
Kubernetes GitOps featuring GitHub, Kustomize and ArgoCDKubernetes GitOps featuring GitHub, Kustomize and ArgoCD
Kubernetes GitOps featuring GitHub, Kustomize and ArgoCD
 
Event driven autoscaling with KEDA
Event driven autoscaling with KEDAEvent driven autoscaling with KEDA
Event driven autoscaling with KEDA
 
Kafka as an Event Store - is it Good Enough?
Kafka as an Event Store - is it Good Enough?Kafka as an Event Store - is it Good Enough?
Kafka as an Event Store - is it Good Enough?
 
PayPal's History of Microservices Architecture
PayPal's History of Microservices ArchitecturePayPal's History of Microservices Architecture
PayPal's History of Microservices Architecture
 
Graal and Truffle: One VM to Rule Them All
Graal and Truffle: One VM to Rule Them AllGraal and Truffle: One VM to Rule Them All
Graal and Truffle: One VM to Rule Them All
 
Architecture patterns for distributed, hybrid, edge and global Apache Kafka d...
Architecture patterns for distributed, hybrid, edge and global Apache Kafka d...Architecture patterns for distributed, hybrid, edge and global Apache Kafka d...
Architecture patterns for distributed, hybrid, edge and global Apache Kafka d...
 
Practical tips and tricks for Apache Kafka messages integration | Francesco T...
Practical tips and tricks for Apache Kafka messages integration | Francesco T...Practical tips and tricks for Apache Kafka messages integration | Francesco T...
Practical tips and tricks for Apache Kafka messages integration | Francesco T...
 
Improving Performance of Micro-Frontend Applications through Error Monitoring
Improving Performance of Micro-Frontend Applications through Error MonitoringImproving Performance of Micro-Frontend Applications through Error Monitoring
Improving Performance of Micro-Frontend Applications through Error Monitoring
 
Spring I/O 2022: Knative and Spring - Bringing back the `func`
Spring I/O 2022: Knative and Spring - Bringing back the `func`Spring I/O 2022: Knative and Spring - Bringing back the `func`
Spring I/O 2022: Knative and Spring - Bringing back the `func`
 
Application Modernization: Migrating Mainframe Apps to the Cloud Using Spring
Application Modernization: Migrating Mainframe Apps to the Cloud Using SpringApplication Modernization: Migrating Mainframe Apps to the Cloud Using Spring
Application Modernization: Migrating Mainframe Apps to the Cloud Using Spring
 

Ähnlich wie Saga pattern

Ähnlich wie Saga pattern (20)

SAP Gateway scalability testing
SAP Gateway scalability testingSAP Gateway scalability testing
SAP Gateway scalability testing
 
Understanding of the scope of work
Understanding of the scope of workUnderstanding of the scope of work
Understanding of the scope of work
 
Complex event processing platform handling millions of users - Krzysztof Zarz...
Complex event processing platform handling millions of users - Krzysztof Zarz...Complex event processing platform handling millions of users - Krzysztof Zarz...
Complex event processing platform handling millions of users - Krzysztof Zarz...
 
The Dual write problem
The Dual write problemThe Dual write problem
The Dual write problem
 
Tying Automation to the Line of Business
Tying Automation to the Line of BusinessTying Automation to the Line of Business
Tying Automation to the Line of Business
 
65% Performance Gains at Cryptocurrency Platform CoinGecko: An Argo Smart Rou...
65% Performance Gains at Cryptocurrency Platform CoinGecko: An Argo Smart Rou...65% Performance Gains at Cryptocurrency Platform CoinGecko: An Argo Smart Rou...
65% Performance Gains at Cryptocurrency Platform CoinGecko: An Argo Smart Rou...
 
Event Detection Pipelines with Apache Kafka
Event Detection Pipelines with Apache KafkaEvent Detection Pipelines with Apache Kafka
Event Detection Pipelines with Apache Kafka
 
Hadoop application architectures - Fraud detection tutorial
Hadoop application architectures - Fraud detection tutorialHadoop application architectures - Fraud detection tutorial
Hadoop application architectures - Fraud detection tutorial
 
Encode
EncodeEncode
Encode
 
Algorand Educate: Intro to Algorand
Algorand Educate: Intro to AlgorandAlgorand Educate: Intro to Algorand
Algorand Educate: Intro to Algorand
 
WebRTC Summit November 2013 - WebRTC Interoperability (and why it is important)
WebRTC Summit November 2013 - WebRTC Interoperability (and why it is important)WebRTC Summit November 2013 - WebRTC Interoperability (and why it is important)
WebRTC Summit November 2013 - WebRTC Interoperability (and why it is important)
 
Virtual Flink Forward 2020: Data driven matchmaking streaming at Hyperconnect...
Virtual Flink Forward 2020: Data driven matchmaking streaming at Hyperconnect...Virtual Flink Forward 2020: Data driven matchmaking streaming at Hyperconnect...
Virtual Flink Forward 2020: Data driven matchmaking streaming at Hyperconnect...
 
Best Practices for Troubleshooting Four Real-world Java Performance Issues
Best Practices for Troubleshooting Four Real-world Java Performance IssuesBest Practices for Troubleshooting Four Real-world Java Performance Issues
Best Practices for Troubleshooting Four Real-world Java Performance Issues
 
Hadoop application architectures - Fraud detection tutorial
Hadoop application architectures - Fraud detection tutorialHadoop application architectures - Fraud detection tutorial
Hadoop application architectures - Fraud detection tutorial
 
Ramco Enterprise Asset Management (EAM) Solution - Overview
Ramco Enterprise Asset Management (EAM) Solution - OverviewRamco Enterprise Asset Management (EAM) Solution - Overview
Ramco Enterprise Asset Management (EAM) Solution - Overview
 
Real World Problem Solving Using Application Performance Management 10
Real World Problem Solving Using Application Performance Management 10Real World Problem Solving Using Application Performance Management 10
Real World Problem Solving Using Application Performance Management 10
 
Amazon SageMaker for Fraud Detection
Amazon SageMaker for Fraud DetectionAmazon SageMaker for Fraud Detection
Amazon SageMaker for Fraud Detection
 
Redis Day TLV 2018 - 5 Redis Use Cases That Power the Datorama Query API
Redis Day TLV 2018 - 5 Redis Use Cases That Power the Datorama Query APIRedis Day TLV 2018 - 5 Redis Use Cases That Power the Datorama Query API
Redis Day TLV 2018 - 5 Redis Use Cases That Power the Datorama Query API
 
NoSQL meetup July 2011
NoSQL meetup July 2011NoSQL meetup July 2011
NoSQL meetup July 2011
 
Why And When Should We Consider Stream Processing In Our Solutions Teqnation ...
Why And When Should We Consider Stream Processing In Our Solutions Teqnation ...Why And When Should We Consider Stream Processing In Our Solutions Teqnation ...
Why And When Should We Consider Stream Processing In Our Solutions Teqnation ...
 

Mehr von HYS Enterprise

Evgeniy Burak (HYS Enterprise): “Spring Data REST or intellectual job VS manual”
Evgeniy Burak (HYS Enterprise): “Spring Data REST or intellectual job VS manual”Evgeniy Burak (HYS Enterprise): “Spring Data REST or intellectual job VS manual”
Evgeniy Burak (HYS Enterprise): “Spring Data REST or intellectual job VS manual”
HYS Enterprise
 

Mehr von HYS Enterprise (20)

Magic of web components
Magic of web componentsMagic of web components
Magic of web components
 
“ASP.NET Core. Features and architecture”
“ASP.NET Core. Features and architecture” “ASP.NET Core. Features and architecture”
“ASP.NET Core. Features and architecture”
 
How to create a perfect CV and make a good impression at an interview
How to create a perfect CV and make a good impression at an interviewHow to create a perfect CV and make a good impression at an interview
How to create a perfect CV and make a good impression at an interview
 
Top soft skills to get a job
Top soft skills to get a jobTop soft skills to get a job
Top soft skills to get a job
 
Wild Async .NET world: AID Kit for boy-scouts
Wild Async .NET world: AID Kit for boy-scoutsWild Async .NET world: AID Kit for boy-scouts
Wild Async .NET world: AID Kit for boy-scouts
 
Contract testing. Getting started with Pact IO.
Contract testing. Getting started with Pact IO.Contract testing. Getting started with Pact IO.
Contract testing. Getting started with Pact IO.
 
Testing strategies in a microservices architecture. Independence vs integration
Testing strategies in a microservices architecture.  Independence vs integrationTesting strategies in a microservices architecture.  Independence vs integration
Testing strategies in a microservices architecture. Independence vs integration
 
Leonid Sushenko "Pro scrum"
Leonid Sushenko "Pro scrum"Leonid Sushenko "Pro scrum"
Leonid Sushenko "Pro scrum"
 
"Test Design Techniques"
"Test Design Techniques" "Test Design Techniques"
"Test Design Techniques"
 
Essentials soft skills for a developer
Essentials soft skills for a developerEssentials soft skills for a developer
Essentials soft skills for a developer
 
“Tips&Tricks&Antitricks with .Net Core backend in GameDev”
“Tips&Tricks&Antitricks with .Net Core backend in GameDev”“Tips&Tricks&Antitricks with .Net Core backend in GameDev”
“Tips&Tricks&Antitricks with .Net Core backend in GameDev”
 
"Dealing with legacy code"
"Dealing with legacy code""Dealing with legacy code"
"Dealing with legacy code"
 
“QA job interview: life hacks and scripts for success”
“QA job interview: life hacks and scripts for success”“QA job interview: life hacks and scripts for success”
“QA job interview: life hacks and scripts for success”
 
Evgeniy Burak (HYS Enterprise): “Spring Data REST or intellectual job VS manual”
Evgeniy Burak (HYS Enterprise): “Spring Data REST or intellectual job VS manual”Evgeniy Burak (HYS Enterprise): “Spring Data REST or intellectual job VS manual”
Evgeniy Burak (HYS Enterprise): “Spring Data REST or intellectual job VS manual”
 
Dmitriy Mustafin (HYS Enterprise) "Web UI for Back-end developer."
Dmitriy Mustafin (HYS Enterprise) "Web UI for Back-end developer."Dmitriy Mustafin (HYS Enterprise) "Web UI for Back-end developer."
Dmitriy Mustafin (HYS Enterprise) "Web UI for Back-end developer."
 
Nikolay Tsyb (HYS Enterprise) "Immortal system as a piece of cake."
Nikolay Tsyb (HYS Enterprise) "Immortal system as a piece of cake."Nikolay Tsyb (HYS Enterprise) "Immortal system as a piece of cake."
Nikolay Tsyb (HYS Enterprise) "Immortal system as a piece of cake."
 
Я твой Expected Result шатал
Я твой Expected Result шаталЯ твой Expected Result шатал
Я твой Expected Result шатал
 
“Elasticsearch for .NET developers”
“Elasticsearch for .NET developers”  “Elasticsearch for .NET developers”
“Elasticsearch for .NET developers”
 
“Microservices: how to avoid making the same mistake twice.”
“Microservices: how to avoid making the same mistake twice.”“Microservices: how to avoid making the same mistake twice.”
“Microservices: how to avoid making the same mistake twice.”
 
Cheap and Cheerful: Useful Tools for Fast Development of Ready-Made Solutions
Cheap and Cheerful: Useful Tools for Fast Development of Ready-Made SolutionsCheap and Cheerful: Useful Tools for Fast Development of Ready-Made Solutions
Cheap and Cheerful: Useful Tools for Fast Development of Ready-Made Solutions
 

Kürzlich hochgeladen

Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills KuwaitKuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
jaanualu31
 
notes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptnotes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.ppt
MsecMca
 
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
HenryBriggs2
 
+97470301568>> buy weed in qatar,buy thc oil qatar,buy weed and vape oil in d...
+97470301568>> buy weed in qatar,buy thc oil qatar,buy weed and vape oil in d...+97470301568>> buy weed in qatar,buy thc oil qatar,buy weed and vape oil in d...
+97470301568>> buy weed in qatar,buy thc oil qatar,buy weed and vape oil in d...
Health
 

Kürzlich hochgeladen (20)

Minimum and Maximum Modes of microprocessor 8086
Minimum and Maximum Modes of microprocessor 8086Minimum and Maximum Modes of microprocessor 8086
Minimum and Maximum Modes of microprocessor 8086
 
Computer Networks Basics of Network Devices
Computer Networks  Basics of Network DevicesComputer Networks  Basics of Network Devices
Computer Networks Basics of Network Devices
 
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
 
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills KuwaitKuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torque
 
notes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptnotes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.ppt
 
Online food ordering system project report.pdf
Online food ordering system project report.pdfOnline food ordering system project report.pdf
Online food ordering system project report.pdf
 
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
 
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced LoadsFEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
 
Air Compressor reciprocating single stage
Air Compressor reciprocating single stageAir Compressor reciprocating single stage
Air Compressor reciprocating single stage
 
Hostel management system project report..pdf
Hostel management system project report..pdfHostel management system project report..pdf
Hostel management system project report..pdf
 
kiln thermal load.pptx kiln tgermal load
kiln thermal load.pptx kiln tgermal loadkiln thermal load.pptx kiln tgermal load
kiln thermal load.pptx kiln tgermal load
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leap
 
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
 
+97470301568>> buy weed in qatar,buy thc oil qatar,buy weed and vape oil in d...
+97470301568>> buy weed in qatar,buy thc oil qatar,buy weed and vape oil in d...+97470301568>> buy weed in qatar,buy thc oil qatar,buy weed and vape oil in d...
+97470301568>> buy weed in qatar,buy thc oil qatar,buy weed and vape oil in d...
 
Rums floating Omkareshwar FSPV IM_16112021.pdf
Rums floating Omkareshwar FSPV IM_16112021.pdfRums floating Omkareshwar FSPV IM_16112021.pdf
Rums floating Omkareshwar FSPV IM_16112021.pdf
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdf
 
Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.
 
Engineering Drawing focus on projection of planes
Engineering Drawing focus on projection of planesEngineering Drawing focus on projection of planes
Engineering Drawing focus on projection of planes
 
A Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityA Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna Municipality
 

Saga pattern

  • 1. Saga Pattern By Alexandr Prygun Saga Pattern Play hys-enterprise.com
  • 2. HYS Enterprise is a Dutch software development company with more than 200 talented engineers from all over the world hys-enterprise.com UkraineNetherlands
  • 3. My experience 5+ years experience .NET Developer / Team Lead in HYS Enterprise Saga pattern
  • 4. Monolith App Saga Pattern API Application Database One call One transactionIncoming call
  • 5. Saga Patterm API Gateway Application 1 Database 1 Application 2 Database 2 Application 3 Database 3 Incoming call SOA/Microservices App
  • 6. Saga Pattern 2PC: Prepare Phase API Gateway Application 1 Database 1 Application 2 Database 2 Application 3 Database 3 Incoming call Propose Vote Propose Vote Propose Vote
  • 7. Saga Pattern 2PC: Commit Phase API Gateway Application 1 Database 1 Application 2 Database 2 Application 3 Database 3 Incoming call Commit/Abort Done Commit/Abort Done Commit/Abort Done
  • 8. Saga Pattern 2PC: Disadvantages - Data stays locked until commit or abort command - There is no mechanism to rollback other transactions in case one service fails - Others have to wait until the slowest resource finish its confirmation. - Bad scaling
  • 9. Saga Pattern Sagas History Long Live Transactions Hector Garcia-Molina, Kenneth Salem, Princeton University, 1987
  • 10. Saga Pattern What is Saga? - Saga is long-lived transaction - Saga is collection of sub-transactions
  • 11. Saga Pattern Saga orchestrator Hotel Booking Service Database 1 Rent Car Service Database 2 Flight Tickets Service Database 3 Book Trip Start saga Start book hotel End book hotel Start book car End book car Start book tickets End book tickets End saga
  • 12. Saga Pattern Saga choreography Hotel Booking Service Database 1 Rent Car Service Database 2 Flight Tickets Service Database 3 Book Trip Start saga Hotel is booked Car is booked End saga Tickets are booked
  • 13. Saga Pattern Unsuccessful Saga Start saga 1. Start book hotel 2. End book hotel 3. Start book car 4. End book car 5. Start book flights 6. Flights booking fail Abort saga 7. Start cancel car 8. End cancel car 9. Start cancel hotel 10. End cancel hotel End saga Commit steps Rollback steps
  • 14. Saga Pattern Saga pros and cons Main advantage is that it helps maintain data consistency across multiple services without tight coupling. Main disadvantage is the complexity from a programming point of view. Compensating transaction should be designed.
  • 15. Saga Pattern Saga tips - A unique distributed transaction ID should be created for each saga and it should be present in each related command or event - Saga commands should be idempotent - All components should implement compensate commands handlers - Compensate commands should be idempotent as well - Avoid synchronous operations
  • 16. Thank you For your attention! Any Questions? Event Name