Try
↑ ↓ move↵ openesc close

Interview prep / Two-phase commit

Junior · Two-phase commit · System design interview question

Walk through the two phases of two-phase commit.

Sketch your own answer first, then compare it with the one below.

A strong answer

In the prepare phase, the coordinator sends a prepare request to every participant. Each participant makes its changes durable, keeps its locks, and replies yes or no. A yes is a promise: it will commit if told to, even after a crash.

In the commit phase, the coordinator writes its decision to its own log. Commit if every vote was yes, abort otherwise. It then sends the decision, and each participant applies it, releases its locks and acknowledges.

Two points to name. The yes vote is the point of no return for the participant. The decision is final once the coordinator has logged it.

Sources

Learn it by running it

The two-phase commit lesson explains the mechanism behind this question, and its lab lets you change the parameters and watch the effect.

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