Two-Phase Commit(2PC) — Distributed Design Patterns
3 min readMay 8, 2023
The Two-Phase Commit protocol is a distributed algorithm that ensures that a transaction is either committed or rolled back consistently across all nodes in a distributed system. The protocol involves two phases, as the name suggests.
Phase 1 — Prepare Phase: The coordinator node sends a prepare message to all participating nodes, asking them if they are ready to commit the transaction. Each participant acquires a “lock” on the resource/s and replies with either a Yes or No message, indicating whether they can commit.