By WalkingTree   December 10,  2020

Transaction handling in Microservices

It’s challenging to handle the transition from a monolith to a microservice architecture. Transaction handling is the center of this issue. A typical database transaction done in a web application using local transactions is now a complicated distributed transaction problem. 

In old monolith applications, we mainly used ACID transactions, which are usually found in relational database systems. We wrap the individual debit and credit operations in an ACID transaction. This avoids inconsistencies such as money being lost from the system if the funds were taken out from one account but not put into the other. 

Selecting the correct transaction model for your microservices structure is crucial. Any technology we use while implementing transactions, we need to be explicit on the data consistency that each approach will give. Then cross-check with the business needs to see what is most suitable. Let’s look at some of the tips for getting started: 

2PC – In case the microservices are created using different programming languages, and probably development teams from different companies, it is not possible to combine all operations in a single service. It would require strict data consistency.

Compensation-based transactions – Use a transaction coordination mechanism to track the individual steps in a transaction, and in case of a failure, execute compensation operations. 

Consolidating services – Use this in case 2PC is not compatible due to performance issues and scalability, but strict data consistency is required for business needs. In this case, group related functionality to their own single services and use local transactions. 

Read on to know more about transaction handling in Microservices.

Blogs

Privacy Preferences
When you visit our website, it may store information through your browser from specific services, usually in form of cookies. Here you can change your privacy preferences. Please note that blocking some types of cookies may impact your experience on our website and the services we offer.