Saga Pattern in-depth analysis. Convert a monolithic architecture to microservice architecture analysis. Why need orchestration in-depth analysis. Rollback mechanism of SAGA how work. These covered in this slide.
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
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
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