Learning path

Full curriculum

Full curriculum

Arrows go from each prerequisite to the units that depend on it. Hover or focus a unit to highlight its path.

Unit content

Distributed transactions and two-phase commit

A distributed transaction spans state managed by more than one independent participant, such as two databases or two shards.

Two-phase commit (2PC) coordinates one atomic decision through a coordinator.

In the prepare phase, each participant records enough durable state to promise whether it can commit. If every participant votes yes, the coordinator records a commit decision; otherwise it records abort.

In the decision phase, the coordinator tells participants to commit or abort according to that recorded outcome.

The protocol can preserve atomicity across participant crashes when its durable records are recovered correctly, but it can block. A prepared participant may be unable to decide safely while the coordinator or required decision information is unavailable.

2PC therefore solves atomic commitment, not general consensus or permanent availability.