Maintain data consistency in a microservice architecture

Bernardo Teixeira
5 min readMay 22, 2023

The problem with microservices is that you really can’t have ACID transactions. Sure, you can have ACID transactions inside a microservice, but not when you have a transaction with multiple microservices. But implementing SAGA Design will help with this problem.

Let’s take this example: I have an online store. With four microservices, the payment microservice, the order microservice, the shipping microservice, and the stock microservice.

The application will create an order.

The Order microservice will publish a message to get the stock, payment, and shipping availability. Like the diagram below. If we have stock, the payment has been done and the shipping is available you don’t have anything to worry about. The problem is when you have some problems. No stock or the payment failed or the shipping is not available. Also, with this type of flow/responsibilities, the Order microservice is responsible for the orders and also responsible to know the flow inside of your application. And you don’t want that, because if your application starts to grow your Order microservice will become a huge monolithic.

--

--