2-Phase Commit (2PC)
Let's explore how the 2-phase commit algorithm helps to achieve atomicity.
In a distributed system with an unreliable network, just sending a message to the involved nodes would not be enough for executing a distributed transaction. The node initiating the transaction would not know whether the other nodes committed successfully, or aborted because of some failure, to make a final decision about the result of the transaction.
When we think about it, the simplest idea is to add another round of messages, and check what the result was on each node. This is essentially the
2-phase commit protocol J. N. Gray, “Notes on database operating systems,” Operating Systems. Lecture Notes in Computer Science, vol 60. Springer, 1978. . (2PC) B. Lampson and H. E. Sturgis, “Crash Recovery in a Distributed Data Storage System,” 1979.
Phases
The 2-phase commit protocol consists of two phases, hence the name.
The protocol contains two different roles. Their names reflect their actual responsibilities in the protocol.
-
The coordinator is responsible for coordinating the different phases of the protocol
-
The participants correspond to all the nodes that participate in the transaction
Note that one of the participants could also play the role of the coordinator.
Get hands-on with 1400+ tech skills courses.