Comparing Various Methods of Distributed Transactions

Explore the different ways to handle consistency across a distributed system.

In this lesson, we will look at three ways to handle consistency across a distributed system:

  • Two-phase commit (2PC) can offer the strongest consistency but has some large drawbacks.

  • The other two are the choreographed saga and the orchestrated saga, which still offer a good consistency model and are excellent options when 2PCs are not an option.

The 2PC

At the center of a 2PC is a coordinator that sends the “Prepare” and “Commit” messages to all the participants. During the Prepare phase, each participant can respond positively to signify they have started a local transaction and are ready to proceed. If all the participants have responded positively, then the coordinator will send a COMMIT message to all of the participants and the distributed transaction will be complete. On the other hand, if any participant responds negatively during the Prepare phase, then the coordinator will send an ABORT message to inform the other participants to roll back their local transaction; again, the distributed transaction will be complete:

Get hands-on with 1400+ tech skills courses.