spring-bootmicroservicesdistributed-transactions

Transaction management in microservices


We are rewriting legacy app using microservices. Each microservice has its own DB. There are certain api calls that require to call another microservice and persist data into both DBs. How to implement distributed transaction management effectively in this case?

Since we are not migrated completely to the new micro services environment, we still writeback data to old monolith. For this when an microservice end point is called, we call monolith service from microservice api to writeback same data. How to deal with the same problem in this case as well.

Thanks in advance.


Solution

  • There are different distributer transaction frameworks usually included and maintained as part of heavy application servers like JBoss and WebLogic.

    The standard usually used by such services is Jakarta Transactions (JTA; formerly Java Transaction API).

    Tomcat and Spring don't support distributed transactions out-of-the-box. You can add this functionality using third party framework like Atomikos (just googled, I've never used it).

    But remember, microservice with JTA ist not "micro" anymore :-)

    Here is a small overview over available technologies and possible workarounds:

    https://www.baeldung.com/transactions-across-microservices