By WalkingTree June 24, 2020
With the adoption of ‘Database Per Service’ in a microservices architecture every service gets its separate database. However, there’s a problem with how to ensure data consistency among different services.
Let’s take a look at an example here. You are implementing the order function on an e-commerce website. When the user places an order, the application will call for the stock service to update the number of product purchases. This will later go to the shipping service to deliver the product to the user.
But there’s a problem here. What if the quantity of the product is less than the quantity user ordered? Or what if there’s a problem with shipping? Orders and shipping are quite different databases so there’s no chance of using a local ACID transaction.
What is SAGA?
SAGA pattern has been used widely for the past two decades. There are many ways of implementing SAGA but we are going to focus on mainly two of them – Choreography and Orchestrator.
If you are about dance, then choreography is a sequence of steps or movements. It is also quite similar in software development. Let’s apply the choreography method in an e-commerce application.
- Order service has to create a record in the database with the status “Verifying’
- Order services publish an event ‘Order is successfully placed’
- The stock services update the number of products
- Publishes an event ‘Product is updated successfully’
- The status is changed to ‘Shipping’
- Shipping service creates a record and publishes an event ‘Shipping is registered successfully’
- The status is changed to ‘Finish’
In this method, a process manager is added as an orchestrator. This process manager is responsible for identifying the events and triggering the endpoints. Instead of having an order service, stock service, and shipping service in the choreography method, here you can just implement a process manager and all these 2 services will listen to this.
Read on to know more about SAGA and how to actually implement these 2 methods.
DevOps is the most recent tech absorption in enterprises with close sync between software development and IT operations…
Problem statement Before the advent of Microservices, we used to create a properties files in which we maintained…
As we all know, Microservices brought in a paradigm shift in the way we think, design and architect…
In my recent articles, I covered the core building blocks of DevOps in Microservices and Pitfalls of each…
In my previous article, I covered the core building blocks of DevOps in Microservices environment. As part of…