What is SAGA pattern and how important is it — WalkingTree Technologies

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.

SAGA Choreography

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’

SAGA Orchestration

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.

to know more about SAGA and how to actually implement these 2 methods.

Originally published at https://walkingtree.tech on June 24, 2020.




WalkingTree is an IT software and service provider recognized for its passion for technology.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Day 23 — Tired

Raspberry Pi Model 2 B Electronics Project — Part 1

28 Project Ideas to Practice Your Programming Skills

UI journey of .NET tutor-10-Certified in Responsive Web Design by freeCodeCamp

Mattermost 5.15:

Why Pure Code Is a Waste of Time and Clean Code Is More Than Enough

You are doing testing wrong

How to convert .csv to .sqlite using python

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
WalkingTree Technologies

WalkingTree Technologies

WalkingTree is an IT software and service provider recognized for its passion for technology.

More from Medium

How to Apply MBTI in HR: Motivation for every day

The Application Level Window Signaling (ALWS) pattern you probably need

How Do You Become Good at Delivering Software according to DORA metrics?

What is AsyncAPI?