...

/

Introduction to Two-Phase Commit (2PC)

Introduction to Two-Phase Commit (2PC)

Learn about the two-phase commit and the motivation behind its creation.

Two-phase commit (2PC) is a distributed consensus algorithm that was historically developed in the context of database transactions. A transaction is an abstraction that usually provides the ACIDA=Atomicity, C=Application's notion of Consistency, I=Isolation between any concurrent transactions, and D=Durability of the committed transaction data. correctness guarantees to the end programmers. The “A” in ACID refers to atomicity—a transaction either commits in total or aborts; in other words, something happens completely or it doesn’t occur at all. When we want different systems to either commit or abort together, we use the 2PC algorithm. In the context of transactions, the consensus is about the binary decision of either committing or aborting among all the participants in the 2PC protocol.

A common use case for 2PC is when a transaction reads and writes multiple database shards, and an application wants to ensure that all such changes happen as one unit. In this case, consensus means that every participant should be on the same page. The 2PC algorithm can be used in any scenario that requires atomicity across all participants. ...