- Modern technologies won't support it (RabbitMQ, Kafka, etc.);
- This is a form of using Inter-Process Communication in a synchronized way and this reduces availability;
- All participants of the distributed transaction need to be avaiable for a distributed commit, again: reduces availability.
Implementing business transactions that span multiple services is not straightforward. Distributed transactions are best avoided because of the CAP theorem. Moreover, many modern (NoSQL) databases don’t support them. The best solution is to use the Saga Pattern.
[...]
One of the most well-known patterns for distributed transactions is called Saga. The first paper about it was published back in 1987 and has it been a popular solution since then.
There are a couple of different ways to implement a saga transaction, but the two most popular are:
- Events/Choreography: When there is no central coordination, each service produces and listen to other service’s events and decides if an action should be taken or not;
- Command/Orchestration: when a coordinator service is responsible for centralizing the saga’s decision making and sequencing business logic;
Starbucks Does Not Use Two-Phase Commit
Excellent articles from 2004 and 2005 written by Gregor Hohpe, co-creator of the EIP book, about error handling in distributed systems:
Error-handling strategies for loosely coupled systems
Basically, both articles say that when we try to write 2 or more systems in a business transaction and one of them fails, we have 4 strategies to do error handling:
Those strategies are exactly the ones discussed in this amazing talk: Six Little Lines of Fail
Other contents