Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Transactions in microservices

Tags:

I have read some articles about microservices architecture, but no one takes the topic of transaction. All that they says that this is hard to do it. Maybe someone can describe how to handle this?

But not from domain side, but from technology side. Lets say that we have business case where we need to invoke two different services and both of them make some changes on database. But how to rollback if some error occurs on the second one?

Who knows some libraries or design patter for this problem?

like image 267
KirkoR Avatar asked Jul 10 '14 12:07

KirkoR


People also ask

How transactions are managed in microservices?

Prepare phase — during this phase, all participants of the transaction prepare for commit and notify the coordinator that they are ready to complete the transaction. Commit or Rollback phase — during this phase, either a commit or a rollback command is issued by the transaction coordinator to all participants.

How database transactions are handled in microservices?

A transaction is distributed to multiple services that are called sequentially or parallelly to complete the entire transaction. With a microservices architecture, the most common pattern is database per microservice, so transactions also need to span across different databases.

What are transactions in distributed systems?

A distributed transaction is a set of operations on data that is performed across two or more data repositories (especially databases). It is typically coordinated across separate nodes connected by a network, but may also span multiple databases on a single server.


1 Answers

I may not be the ultimate expert in this, but I'm sure you're heading towards the Distributed Transactions. In order to have them running, all the application service components need a common shared transaction id, and you have to make sure that every component is informed about the state of the transaction. It is asynchronous, so you'll require substantial prog skills.

Here are distributed transactions mentioned or discussed:

https://en.wikipedia.org/wiki/Distributed_transaction

http://contino.co.uk/microservices-not-a-free-lunch/

http://martinfowler.com/articles/microservices.html

It would seem people try to avoid it as it is difficult. Maybe that's why you don't find much about.

Hope this helps a step forward :-)

like image 60
peter_the_oak Avatar answered Sep 25 '22 23:09

peter_the_oak