SlideShare a Scribd company logo
2
Most read
3
Most read
13
Most read
Journey of SAGA pattern
in Micro-service
Architecture
Presented by Anisur Rahman
9:26 AM
Refactoring Monolith to Micro-services
 Two refactoring strategies:
 Strategy 1: Implement new functionality as services
 Strategy 2: Extract services from the monolith
5 Steps:
 Step 0: Review AS-IS code
 Step 1: Split the code
 Step 2: Split the database
 Step 3: Define a standalone “Delivery service”
 Step 4: Use the standalone “Delivery service”
 Step 5: Remove the delivery management functionality from
the FTGO monolith
9:26 AM
Strategy 1: Implement new functionality as services
Story
Micro
Service
Micro
Service
Micro
Service
Database
Database
Database
9:26 AM
Strategy 2: Extract services from the monolith
9:26 AM
Review codebase, client-
domain interaction, database
Step 0: Review Monolith code
9:26 AM
Step 1: Split the code
Convert delivery management into a separate, loosely coupled module within the monolith
9:26 AM
Step 2: Split the database
Split the database and define a separate database schema for the Delivery service module
9:26 AM
Step 3: Define a standalone “Delivery service”
Just define a standalone service but don’t use it
9:26 AM
Step 4: Use the standalone “Delivery service”
Start using that standalone service
9:26 AM
Step 5: Remove the delivery management functionality from the FTGO
monolith Remove Delivery related code from Order Management Service
9:26 AM
Maintain data consistency in Micro service
Architecture
2PC Event Sourcing SAGA
9:26 AM
Need to know ACID transaction before
SAGA (recap)
 Atomicity: Transaction either completes fully or fails
completely.
 Consistency: Maintain the logical consistency, no matter
of its final outcome.
 Isolation: Multiple transactions occur concurrently
without causing inconsistency of database state
 Durability: Durability means that committed transactions
remain committed irrespective of any type of system
failure.
9:26 AM
What is SAGA?
 A pattern that maintain data consistency across services
using a sequence of local transactions that are
coordinated using asynchronous messaging.
 Maintain data consistency
 Sequence of local transactions.
 Each local transaction updates data within a single
service using the ACD transactions.
 Asynchronous messaging occur in SAGA
9:26 AM
SAGA
Lets see an example to understand the SAGA pattern & its characteristics:
Make
Order
Create
Order
Update
inventory
Regular
shopping
Return
Order Status
9:26 AM
SAGA implementation
 2 ways are most popular to implement SAGA:
 SAGA — Choreography
 Event based
 Each service communicate with each other via Message Broker
 SAGA — Orchestration
 Command based
 Orchestrator is own a service
 Each service communicate with Orchestrator
9:26 AM
SAGA - Choreography
Order Service
Inventory
Service
Shipping
Service
Inventory DB
9:26 AM
SAGA – Choreography - Rollback
Order Service
Inventory
Service
Shipping
Service
Inventory DB
9:26 AM
SAGA –
Orchestration
Inventory Service
Inventory DB
9:26 AM
Inventory Service
Inventory DB
SAGA –
Orchestration –
Rollback
9:26 AM
Really why you need Orchestration?
 3 main reasons I found through my R&D:
 A second transaction willing to change the same target object,
you can easily put it on hold on the orchestrator until the first
transaction ends. (Isolation problem solved)
 Easier rollback management
 Either I use Choreography OR Orchestration, I must have to create
a SEC. So, in Orchestration the Orchestrator act as a SEC. This
gives me more flexibility. SEC will maintain Audit log. If I use SEC
in Choreography then it will create a Event Sourcing Anti Pattern.
How can Choreography maintain Isolation?
 Use Counter measure design pattern: Semantic lock + Saga status
9:26 AM
When need to apply Rollback mechanism?
 Two type of error can occur through SAGA pattern:
 Technical Error:
 Reasons to occur: Database Connection Lost, Service down for any reason,
Code level Bug
 Solution: Use Message Broker for RETRY mechanism
 Business Error:
 Reasons to occur: Business rules violation
 Solution: Apply Compensate transactions
9:26 AM
Next Topic
Message Broker (RabbitMQ)
9:26 AM
Thank you
9:26 AM

More Related Content

PPTX
Saga about distributed business transactions in microservices world
PDF
Distributed sagas a protocol for coordinating microservices
PPTX
Microservices in the Apache Kafka Ecosystem
PPTX
Managing multiple event types in a single topic with Schema Registry | Bill B...
PDF
Getting Started with Confluent Schema Registry
PDF
Confluent Workshop Series: ksqlDB로 스트리밍 앱 빌드
PPTX
[211] HBase 기반 검색 데이터 저장소 (공개용)
PDF
Introducing Saga Pattern in Microservices with Spring Statemachine
Saga about distributed business transactions in microservices world
Distributed sagas a protocol for coordinating microservices
Microservices in the Apache Kafka Ecosystem
Managing multiple event types in a single topic with Schema Registry | Bill B...
Getting Started with Confluent Schema Registry
Confluent Workshop Series: ksqlDB로 스트리밍 앱 빌드
[211] HBase 기반 검색 데이터 저장소 (공개용)
Introducing Saga Pattern in Microservices with Spring Statemachine

What's hot (20)

PPTX
Introduction to microservices
PPTX
Api gateway in microservices
PPTX
MySQL_MariaDB-성능개선-202201.pptx
PDF
Producer Performance Tuning for Apache Kafka
PDF
Enterprise Integration Patterns with Apache Camel
PPTX
Hexagonal architecture with Spring Boot
PPTX
Introduction to Apache Kafka
PPTX
Designing APIs and Microservices Using Domain-Driven Design
PDF
Networking in Java with NIO and Netty
PPTX
Apache kafka
PDF
멀티클라우드 Service Mesh
PPTX
Axon Framework, Exploring CQRS and Event Sourcing Architecture
PDF
Design patterns for microservice architecture
PDF
OSQuery - Monitoring System Process
PPTX
Javax.servlet,http packages
PPTX
Stability Patterns for Microservices
PPTX
Spark + Cassandra = Real Time Analytics on Operational Data
PDF
Spring Framework - AOP
PDF
Data Distribution and Ordering for Efficient Data Source V2
PPTX
RabbitMQ & Kafka
Introduction to microservices
Api gateway in microservices
MySQL_MariaDB-성능개선-202201.pptx
Producer Performance Tuning for Apache Kafka
Enterprise Integration Patterns with Apache Camel
Hexagonal architecture with Spring Boot
Introduction to Apache Kafka
Designing APIs and Microservices Using Domain-Driven Design
Networking in Java with NIO and Netty
Apache kafka
멀티클라우드 Service Mesh
Axon Framework, Exploring CQRS and Event Sourcing Architecture
Design patterns for microservice architecture
OSQuery - Monitoring System Process
Javax.servlet,http packages
Stability Patterns for Microservices
Spark + Cassandra = Real Time Analytics on Operational Data
Spring Framework - AOP
Data Distribution and Ordering for Efficient Data Source V2
RabbitMQ & Kafka
Ad

Similar to Journey of saga pattern in microservice architecture (20)

PDF
All Streams Ahead! ksqlDB Workshop ANZ
PDF
'How to build efficient backend based on microservice architecture' by Anton ...
PDF
How did we move the mountain? - Migrating 1 trillion+ messages per day across...
PPT
PDF
Confluent Tech Talk Korea
PPTX
Autoscale without netscaler_ccceu13
PDF
MongoDB .local London 2019: Migrating a Monolith to MongoDB Atlas – Auto Trad...
PPTX
Building Efficient, Scalable and Resilient Front-end logging service with AWS
PPTX
Building Efficient, Scalable and Resilient Front-end logging service with AWS
PDF
Arsitektur Aplikasi Modern - Faisal Henry Susanto
PPTX
Microservices
PDF
Study Notes - Event-Driven Data Management for Microservices
PPTX
Upcoming NBIA/TCIA Releases
PPTX
Service Fabric – building tomorrows applications today
PPTX
SingleStore & Kafka: Better Together to Power Modern Real-Time Data Architect...
PDF
Zeroth review presentation - eBay Turmeric / SMC
PDF
Refactoring Web Services on AWS cloud (PaaS & SaaS)
PDF
All About Microservices and OpenSource Microservice Frameworks
PDF
Under the hood: SkySQL monitoring
PDF
Load Balancer Device and Configurations.
All Streams Ahead! ksqlDB Workshop ANZ
'How to build efficient backend based on microservice architecture' by Anton ...
How did we move the mountain? - Migrating 1 trillion+ messages per day across...
Confluent Tech Talk Korea
Autoscale without netscaler_ccceu13
MongoDB .local London 2019: Migrating a Monolith to MongoDB Atlas – Auto Trad...
Building Efficient, Scalable and Resilient Front-end logging service with AWS
Building Efficient, Scalable and Resilient Front-end logging service with AWS
Arsitektur Aplikasi Modern - Faisal Henry Susanto
Microservices
Study Notes - Event-Driven Data Management for Microservices
Upcoming NBIA/TCIA Releases
Service Fabric – building tomorrows applications today
SingleStore & Kafka: Better Together to Power Modern Real-Time Data Architect...
Zeroth review presentation - eBay Turmeric / SMC
Refactoring Web Services on AWS cloud (PaaS & SaaS)
All About Microservices and OpenSource Microservice Frameworks
Under the hood: SkySQL monitoring
Load Balancer Device and Configurations.
Ad

Recently uploaded (20)

PDF
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
PPTX
Welding lecture in detail for understanding
PPTX
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
PDF
composite construction of structures.pdf
PPTX
Internet of Things (IOT) - A guide to understanding
DOCX
573137875-Attendance-Management-System-original
PDF
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
PPTX
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd
PDF
Embodied AI: Ushering in the Next Era of Intelligent Systems
PPTX
Construction Project Organization Group 2.pptx
PPTX
OOP with Java - Java Introduction (Basics)
PDF
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
PPTX
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
PDF
R24 SURVEYING LAB MANUAL for civil enggi
PPTX
UNIT 4 Total Quality Management .pptx
PPT
Project quality management in manufacturing
PPT
CRASH COURSE IN ALTERNATIVE PLUMBING CLASS
PPTX
additive manufacturing of ss316l using mig welding
PDF
Automation-in-Manufacturing-Chapter-Introduction.pdf
PPTX
web development for engineering and engineering
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
Welding lecture in detail for understanding
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
composite construction of structures.pdf
Internet of Things (IOT) - A guide to understanding
573137875-Attendance-Management-System-original
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd
Embodied AI: Ushering in the Next Era of Intelligent Systems
Construction Project Organization Group 2.pptx
OOP with Java - Java Introduction (Basics)
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
R24 SURVEYING LAB MANUAL for civil enggi
UNIT 4 Total Quality Management .pptx
Project quality management in manufacturing
CRASH COURSE IN ALTERNATIVE PLUMBING CLASS
additive manufacturing of ss316l using mig welding
Automation-in-Manufacturing-Chapter-Introduction.pdf
web development for engineering and engineering

Journey of saga pattern in microservice architecture

  • 1. Journey of SAGA pattern in Micro-service Architecture Presented by Anisur Rahman 9:26 AM
  • 2. Refactoring Monolith to Micro-services  Two refactoring strategies:  Strategy 1: Implement new functionality as services  Strategy 2: Extract services from the monolith 5 Steps:  Step 0: Review AS-IS code  Step 1: Split the code  Step 2: Split the database  Step 3: Define a standalone “Delivery service”  Step 4: Use the standalone “Delivery service”  Step 5: Remove the delivery management functionality from the FTGO monolith 9:26 AM
  • 3. Strategy 1: Implement new functionality as services Story Micro Service Micro Service Micro Service Database Database Database 9:26 AM
  • 4. Strategy 2: Extract services from the monolith 9:26 AM
  • 5. Review codebase, client- domain interaction, database Step 0: Review Monolith code 9:26 AM
  • 6. Step 1: Split the code Convert delivery management into a separate, loosely coupled module within the monolith 9:26 AM
  • 7. Step 2: Split the database Split the database and define a separate database schema for the Delivery service module 9:26 AM
  • 8. Step 3: Define a standalone “Delivery service” Just define a standalone service but don’t use it 9:26 AM
  • 9. Step 4: Use the standalone “Delivery service” Start using that standalone service 9:26 AM
  • 10. Step 5: Remove the delivery management functionality from the FTGO monolith Remove Delivery related code from Order Management Service 9:26 AM
  • 11. Maintain data consistency in Micro service Architecture 2PC Event Sourcing SAGA 9:26 AM
  • 12. Need to know ACID transaction before SAGA (recap)  Atomicity: Transaction either completes fully or fails completely.  Consistency: Maintain the logical consistency, no matter of its final outcome.  Isolation: Multiple transactions occur concurrently without causing inconsistency of database state  Durability: Durability means that committed transactions remain committed irrespective of any type of system failure. 9:26 AM
  • 13. What is SAGA?  A pattern that maintain data consistency across services using a sequence of local transactions that are coordinated using asynchronous messaging.  Maintain data consistency  Sequence of local transactions.  Each local transaction updates data within a single service using the ACD transactions.  Asynchronous messaging occur in SAGA 9:26 AM
  • 14. SAGA Lets see an example to understand the SAGA pattern & its characteristics: Make Order Create Order Update inventory Regular shopping Return Order Status 9:26 AM
  • 15. SAGA implementation  2 ways are most popular to implement SAGA:  SAGA — Choreography  Event based  Each service communicate with each other via Message Broker  SAGA — Orchestration  Command based  Orchestrator is own a service  Each service communicate with Orchestrator 9:26 AM
  • 16. SAGA - Choreography Order Service Inventory Service Shipping Service Inventory DB 9:26 AM
  • 17. SAGA – Choreography - Rollback Order Service Inventory Service Shipping Service Inventory DB 9:26 AM
  • 19. Inventory Service Inventory DB SAGA – Orchestration – Rollback 9:26 AM
  • 20. Really why you need Orchestration?  3 main reasons I found through my R&D:  A second transaction willing to change the same target object, you can easily put it on hold on the orchestrator until the first transaction ends. (Isolation problem solved)  Easier rollback management  Either I use Choreography OR Orchestration, I must have to create a SEC. So, in Orchestration the Orchestrator act as a SEC. This gives me more flexibility. SEC will maintain Audit log. If I use SEC in Choreography then it will create a Event Sourcing Anti Pattern. How can Choreography maintain Isolation?  Use Counter measure design pattern: Semantic lock + Saga status 9:26 AM
  • 21. When need to apply Rollback mechanism?  Two type of error can occur through SAGA pattern:  Technical Error:  Reasons to occur: Database Connection Lost, Service down for any reason, Code level Bug  Solution: Use Message Broker for RETRY mechanism  Business Error:  Reasons to occur: Business rules violation  Solution: Apply Compensate transactions 9:26 AM
  • 22. Next Topic Message Broker (RabbitMQ) 9:26 AM