Distributed Systems Reference/Distributed Transactions

Two-Phase Commit & Its Limits

Prepare/commit phases, blocking problem, coordinator failure, and why 2PC is rare across microservices but appears in XA and some distributed databases.

4/5Overview: 25m

What 2PC tries to do

Two-Phase Commit — all participants agree to commit or all abort:

  1. Prepare — coordinator asks: can you commit? Participants vote yes/no, hold locks.
  2. Commit — if all yes, coordinator sends commit; else abort.

Atomicity across multiple resource managers (classic XA transactions across two databases).

Why it's problematic

ProblemConsequence
BlockingIf coordinator crashes after prepare, participants hold locks waiting forever
AvailabilityOne slow/failed participant blocks everyone
OperationalRare in polyglot microservices; coupling at commit time

3PC reduces blocking with extra phase — adds complexity, not widely adopted in interviews.

Where 2PC still appears

  • Distributed SQL (some internal commit protocols)
  • Legacy enterprise XA across two RDBMS
  • Verbal contrast: "we don't do 2PC across 12 microservices; we use sagas"

vs single-database transactions

BEGIN … COMMIT on one Postgres — not this topic. Distributed means multiple independent failure domains.

Interview framing

"2PC gives atomicity but hurts availability and blocks on coordinator failure. At scale we prefer eventual consistency with sagas or outbox for cross-service workflows."

Further Reading