Course contentsShow
← Computer Science
Lesson 2720 of 2,87260. Distributed Data and CommunicationFree lesson

Three-Phase Commit (3PC)

Exploring 3PC's additional pre-commit phase, how it reduces blocking compared to 2PC, and its network partition vulnerabilities.

Three-Phase Commit (3PC)

What you'll learn: How Three-Phase Commit extends 2PC with an extra phase to reduce blocking, and why it still struggles with network partitions.

The Core Problem with 2PC

Recall that Two-Phase Commit can block indefinitely if the coordinator crashes after sending PREPARE but before sending COMMIT/ABORT. Participants are stuck waiting, unsure whether to commit or abort, holding locks that freeze the system.

How 3PC Works

Three-Phase Commit adds a pre-commit phase between the voting phase and the final commit:

  1. Phase 1 (Prepare): Coordinator asks all participants "Can you commit?" Just like 2PC.
  2. Phase 2 (Pre-Commit): If all vote YES, the coordinator sends PRE-COMMIT to all participants. Participants acknowledge and know that everyone voted YES—a commit is coming.
  3. Phase 3 (Commit): Coordinator sends the final COMMIT message.

The Key Improvement

The pre-commit phase creates a non-blocking window. If the coordinator crashes after pre-commit but before commit, participants know:

  • Everyone voted YES
  • A commit is inevitable
  • After a timeout, they can safely elect a new coordinator and complete the commit

This eliminates the indefinite blocking problem of 2PC in crash-failure scenarios.

The Critical Weakness: Network Partitions

3PC assumes a synchronous network model with known message delays and timeouts. In reality, networks experience partitions—groups of nodes become isolated from each other.

If a network partition occurs:

  • Some nodes might timeout and elect a new coordinator, deciding to commit
  • Other nodes (in the other partition) might timeout differently and abort
  • Result: Inconsistent state across partitions, violating safety

3PC trades 2PC's blocking problem for partition vulnerability—a dangerous tradeoff in real-world asynchronous networks.

Key Takeaway: Three-Phase Commit reduces blocking by adding a pre-commit phase that allows recovery after coordinator failure, but it sacrifices safety during network partitions, making it rarely used in practice compared to 2PC.