← Lessons

quiz vs the machine

Platinum1780

Databases

The Two Phase Commit Failure Modes

A coordinator gathers votes then orders commit, but a crash at the wrong moment can leave participants blocked holding locks.

5 min read · advanced · beat Platinum to climb

The Two Phases

Two phase commit coordinates an atomic transaction across several nodes. In the prepare phase the coordinator asks every participant to vote. A participant that votes yes must promise it can commit and holds its locks. In the commit phase the coordinator, once all voted yes, tells everyone to commit; if any voted no it tells everyone to abort.

Where It Breaks

The protocol is correct when nothing fails, but failures expose a weakness.

  • If the coordinator crashes after a participant voted yes but before sending the decision, the participant is stuck. It cannot unilaterally commit or abort, because the outcome may already be decided elsewhere.
  • The participant holds its locks while it waits, blocking other transactions.

This is the blocking problem: two phase commit can stall the whole group on a single coordinator failure.

Mitigations

  • Participants can ask each other about the decision, but if all uncertain participants are blocked the group still waits.
  • A persistent transaction log lets a recovered coordinator resume the decision rather than lose it.
  • Three phase commit and consensus based commit reduce blocking by adding rounds or replicating the decision, at higher cost.

Key idea

Two phase commit is atomic but blocking, a coordinator crash after a yes vote can leave participants holding locks with no safe way to decide alone.

Check yourself

Answer to earn rating on the learn ladder.

1. What is the core failure mode of two phase commit?

2. Why can a blocked participant not just decide on its own?

3. How does a persistent transaction log help?