Majd Yafi

Back-end Developer

Front-end Developer

Solution Architect

0

No products in the cart.

Majd Yafi
Majd Yafi
Majd Yafi
Majd Yafi

Back-end Developer

Front-end Developer

Solution Architect

Blog Post

Rollback Multi-Step Process In A Distributed Microservice Environment

Rollback Multi-Step Process In A Distributed Microservice Environment

The short answer to this is SAGA pattern which allows the transaction to rollback when an error has occurred. A typical example is the order, inventory and notification services. In this example, users place orders then the inventory service receives the order id and finally when the inventory completes with success it notifies the user that there order is complete. The user can only see what happens in the foreground (i.e placing the order) where both inventory and notification services both run in the background.

In case of failure where the inventory services has failed to complete its task, the order should also be restored to its original status. This exercise is simple to achieve in a monolith application where models and functions are accessible as well as their responses immediately to the caller. However, in a microservices environment, this is not as straightforward.

So the SAGA pattern is here to help. This pattern promotes two approaches: Orchestration and Choreography. This article simplifies the the former approach.

The chart below simplifies the order steps into three sequential orders.

 

and here’s the sequence diagram for the process.

These services must have an orchestrator that listens to calls and responses, then notifies the relevant objects in a case of rollback. The orchestrator does the following:

  • tells microservices which operation to perform
  • sends messages (events) to microservices to revert back changes
  • manages the state through state machine

 

the dependency diagram for this example is shown below.

 

The notification service is exempt from the SAGA pattern since this service is not deemed critical for the process. If the notification service fails to update the order status, it should reattempt to send a new notification instead of attempting to rollback the order or cancel it.

The orchestrator should have access to both models (Orders, and Inventory) to create the relevant objects but other approaches are also considered where the request can either be send in custom headers or as a REST request (using the façade pattern).

Taggs:
3 Comments
  • Christy 2:17 pm October 22, 2023 Reply

    Thanks for ones marvelous posting! I quite enjoyed reading it,
    you can be a great author. I will make certain to bookmark your blog and will come back very soon. I want to encourage that you
    continue your great writing, have a nice holiday weekend!

  • Colleen 3:15 pm November 23, 2023 Reply

    Ahaa, its nice conversation concerning this post at this place at this blog, I have
    read all that, so now me also commenting here.

  • Dana 4:55 pm November 24, 2023 Reply

    Hmm is anyone else encountering problems with the images on this blog loading?
    I’m trying to determine if its a problem on my end or if
    it’s the blog. Any suggestions would be greatly
    appreciated..

Write a comment

Insert math as
Block
Inline
Additional settings
Formula color
Text color
#333333
Type math using LaTeX
Preview
\({}\)
Nothing to preview
Insert