Try
↑ ↓ move↵ openesc close

Interview prep / Two-phase commit

Junior · Two-phase commit · System design interview question

What problem does two-phase commit solve?

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

A strong answer

A transaction may change data on several machines. The danger is that some commit and others do not, and the data is left half changed.

Two-phase commit makes the outcome the same everywhere. A coordinator first asks every participant whether it can commit. Only if all say yes does the coordinator tell them to commit. If any says no, everyone aborts.

The trade-off is that the participants must wait for the coordinator's decision. That waiting is the cost of agreeing.

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