Skip to main content

Short note: Three-phase commit

Short answer

Three-phase commit (3PC) extends 2PC with a pre-commit phase to prevent blocking on coordinator failure. Phases: canCommit (vote), preCommit (all know Yes votes), doCommit. If coordinator crashes, participants can elect a new coordinator; if any is in preCommit state, they commit, else abort. It avoids blocking but adds one message round.

Write a short note on three phase commit.

The three-phase commit protocol (3PC) is an extension of 2PC that avoids blocking when the coordinator crashes, by adding a pre-commit state between the vote and the commit. Its states satisfy two conditions: there is no state from which a process can move directly to both COMMIT and ABORT, and there is no state in which a process cannot yet make a final decision but can move directly to COMMIT.

Phases

  1. canCommit: the coordinator sends Prepare/canCommit?; participants reply Yes or No. If any No, or a timeout, the coordinator sends abort.
  2. preCommit: if all say Yes, the coordinator sends Pre-commit; participants acknowledge. Now everyone knows that all have voted Yes.
  3. doCommit: after all acknowledgements, the coordinator sends Commit; participants commit and reply.
Coordinator states:
 INIT --canCommit?--> WAIT --all Yes--> PRECOMMIT --acks--> COMMIT
                        |any No/timeout
                        v
                      ABORT

Participant states:
 INIT --Yes--> READY --preCommit--> PRECOMMIT --commit--> COMMIT
   |No          |abort/timeout
   v            v
 ABORT        ABORT

Recovery rule: if the coordinator fails, the participants elect a new one. If any participant is in PRECOMMIT, all can commit; if none is, all can abort. Timeouts drive transitions so the system never blocks indefinitely.

Compared with 2PC: 3PC is non-blocking under crash failures (not for network partitions), but needs one more round of messages, so it costs more and is less used in practice.

✓ Answer checked by Claude Opus 5.5 (high effort)

All Distributed System chapter 8 questions →