Try
↑ ↓ move↵ openesc close

Curriculum · Module 08, Distributed Transactions

Lesson 1 · 7 topics · 32 min · Intermediate · 0/7 done

Two-phase commit

Ask every machine to prepare, then tell them all to commit. It gives atomicity, and it blocks participants when the coordinator crashes at the wrong moment.

What each topic covers

  • Money moves between two databases. Without a shared protocol, a crash can commit one side and not the other.
  • A coordinator collects a yes from every participant, writes down its decision, and tells them all. A yes is a promise.
  • Run transactions across participants, crash the coordinator after the votes, and read what the locks cost.
  • A crash after the votes leaves participants in doubt with locks held. The block lasts as long as the outage.
  • Before the vote a timeout can abort. After a yes it cannot. Asking peers helps only if one of them heard.
  • Three-phase commit removes blocking under crashes alone. Real networks split, and it breaks there.
  • Three quick checks on the yes vote, the in-doubt state and the safe timeout, with the sources behind the lesson.

Topics

  1. 1Half of a transfer3 min
  2. 2Prepare, then commit4 min
  3. 3Crash a coordinator and count the locks8 min
  4. 4The coordinator that does not come back5 min
  5. 5Which timeout is safe5 min
  6. 6Three phases, and why teams skip them4 min
  7. 7Votes, blocking and timeouts3 min

Practise this lesson

8 interview questions on two-phase commit, with worked answers and sources.

Practise these

Your progress is saved in this browser. Sign in to keep it on every device. Privacy · Terms