Two-Phase Commit

A way to ensure consistency in a distributed system


Two Phases

Phase 1
  • coordinator sends "prepare to commit" message
  • subordinates make sure they can do that no matter what happens
  • write the action to a Database Transaction Log to tolerate failures
  • subordinates reply with "ready to commit" message
Phase 2
  • if all ready, send "commit"
  • if anyone fails, send "abort"


Example

two-phase-commit.png

  1. Coordinator: update
  2. Coordinator: prepare to commit
  3. Subordinate: write to log
  4. Subordinate: say "ready"
  5. Coordinator: commit


See also

Sources