Handling Compensation and Rollback in a Synchronous API-Based Saga Choreography for Microservices

Binu S 0 Reputation points
2024-08-01T17:35:05.5033333+00:00

In a microservices-based online order processing system using a saga choreography approach with synchronous API calls, a customer places an order involving multiple microservices: Order Service, Inventory Service, and Payment Service. After successful order placement, the Inventory Service decrements stock, and the Payment Service processes the payment. If a failure occurs during the compensation transaction to refund the payment amount after multiple retries, how can the system automatically roll back the inventory update without manual intervention or introducing a single point of failure, given that no queue mechanism is used and all communication is synchronous?

Developer technologies | ASP.NET | ASP.NET Core
SQL Server | Other
{count} votes

2 answers

Sort by: Most helpful
  1. Erland Sommarskog 121.9K Reputation points MVP Volunteer Moderator
    2024-08-01T21:02:58.2166667+00:00

    The traditional way of doing this is to have a transaction around the whole thing, and which will not commit until every thing is done. How you will implement in your Saga dance number, I don't know, as I am completely unfamiliar with that technology.

    What I can say, speaking from a the traditional database perspective that I come from, is that anything with compensating transactions etc, will be a lot more complex to implement, and it will also look less pretty on account statements and similar things it transactions are booked and then counterbooked within seconds.


  2. Bruce (SqlWork.com) 78,006 Reputation points Volunteer Moderator
    2024-08-02T17:02:40.23+00:00

    The saga pattern is for Async eventually consistent transactions. The pattern requires atomic updates to a persistent store to keep context changes, and updates to the event queue.

    you are just using some of the techniques to implement the pattern. I’m not sure how your transaction orchestrator handles a crash, loss of network, or down data source. Seems like in your design it just results in a series of orphaned transactions. As the data source can go down, it import to atomically log the transaction to the data source before beginning of each saga transaction.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.