The two-phase commit protocol breaks a database commit into two phases to ensure correctness and fault tolerance in a distributed database system.
Consider a transaction coordinator that manages the commits to database stores. As the name suggests, the entire process is divided into two phases:
The following diagram illustrates a successful transaction using the two-phase commit protocol:
The protocol makes the data consistent and available, either all the databases get an update or none do. This protocol ensures that the databases are always synchronized.
The two-phase commit is a blocking protocol; the failure of a single node blocks progress until the node recovers. Moreover, if the transaction coordinator fails, then the database is left in an inconsistent state and only recovers once the coordinator recovers. This leads to another drawback as the protocol’s latency depends on the slowest node. Since it waits for all the nodes to send acknowledgment messages, a single slow node will slow down the entire transaction.
Free Resources