Academy · Consistency & Consensus

2PC, 3PC & the blocking problem

Make N machines commit a transaction all-or-nothing, when any of them can crash mid-handshake.

2 min read·8 sections
Open the interactive version → diagrams, practice & more

The problem

Make N machines commit a transaction all-or-nothing, when any of them can crash mid-handshake.

The idea

Two-Phase Commit: a coordinator asks everyone to "prepare", then tells all to commit only if all voted yes.

How it works

Phase 1 (prepare): participants durably log and vote. Phase 2 (commit/abort): coordinator decides. A YES vote is a binding promise. Its fatal flaw: if the coordinator dies after votes, participants block forever holding locks. 3PC adds a phase to avoid blocking but breaks under network partitions (split brain).

The tradeoff

2PC chooses safety over liveness (can block). 3PC chose liveness but risks inconsistency. Modern systems run 2PC over a consensus group instead.

In the wild

Google Spanner runs 2PC on top of Paxos groups so the coordinator can't be a single point of failure.

Deep dive

Flow

  1. Coordinator sends prepare; participants durably log and vote.
  2. All vote yes → coordinator logs commit and broadcasts it.
  3. Any no or timeout → global abort.
  4. Participants apply the decision and release locks.

Watch for

  • A YES vote is a binding promise — the participant must be able to commit.
  • Coordinator dies post-vote → participants block, holding locks.
  • 3PC unblocks but breaks under network partitions (split brain).

Common trap

Name the blocking flaw, then say modern systems run 2PC over a Paxos/Raft group.

Common questions

What problem does 2PC, 3PC & the blocking problem solve?

Make N machines commit a transaction all-or-nothing, when any of them can crash mid-handshake.

How does 2PC, 3PC & the blocking problem work?

Phase 1 (prepare): participants durably log and vote. Phase 2 (commit/abort): coordinator decides. A YES vote is a binding promise. Its fatal flaw: if the coordinator dies after votes, participants block forever holding locks. 3PC adds a phase to avoid blocking but breaks under…

What are the tradeoffs of 2PC, 3PC & the blocking problem?

2PC chooses safety over liveness (can block). 3PC chose liveness but risks inconsistency. Modern systems run 2PC over a consensus group instead.

Where is 2PC, 3PC & the blocking problem used in production?

Google Spanner runs 2PC on top of Paxos groups so the coordinator can't be a single point of failure.

Part of Academy on SystemLore — system design explained with 148 deep topics, interactive diagrams, and a build-it-yourself game. Browse the glossary and "X vs Y" comparisons, or build this one →