2 Phase commit for distributed transactions has many limitations. Saga is the recommended pattern in microservices for transactions distributed across multiple microservices , where each having its own database. Saga is sequence of local transactions. If one of the local transaction fails , compensating transactions can be used to roll back each of the previous steps.

Context and problem

Typically in monolithic application which uses a RDBMS acid properties of the database can be used to create the illusion that transactions are executing in a seqential faishon (or the transactions have exclusing access to data) , hence eliminating problems like Lost updates  and Dirty Reads. 

If data written by one transaction is

RDBMS can provide isolated transactions but in microservices where each service has its own db, the transactions are not isolated. ie multiple sagas can run concurrently leading to problems like Lost updates and dirty reads.

2 phase commit protocol is an atomic commitment protocol for distributed systems . Note that XA Transactions (2 Phase Commit) 2 has many limitations and is not used much in modern applications now. Note that ejb for instance support distributed transactions which can span multiple ejb deployed on different ejb containers deployed on same or different servers. 

         ie there is choice between consistency and avalaibility and modern architectures favor avalaibility ie either you you a design for a system which is  consistentency oriented (the reads return error or the most recent write) or avalaibility oriented (requests receive a non error response but most recent write is not guranteed).

Solution

Saga pattern can be used manage transactions which span across microservices.

Handling isolation related issues in sagas.

As allready metioned lost updates and dirty reads can happen becuase of lack of isolation in sagas.

Various techniques can be used to handle isolation issues.

                      in the order cancellation saga if delivery cancellation fails as the shipping has allready happened then order cancellation saga has to be rolled back. in which case the increase in wallet balance has to be rolled back , but before it is rolled back , an order creation saga may allready have read the wallet balance leading to dirty read and a situation where order is approved although wallet balance is not there. if the steps of the order saga are reordered in the following way the dirty read problem is solved..

Disadvantages of sagas