Distributed Systems Architecture

Two-Phase Commit (2PC)

An atomic commitment protocol used in distributed systems to ensure that all participating database nodes either commit or abort a distributed transaction together.

Deep Dive

How Two-Phase Commit (2PC) Works in Production

Under-the-hood mechanics and technical implementation details.

Technical Deep Dive

Detailed Architecture

Two-Phase Commit operates via a centralized Coordinator and multiple Resource Cohorts in two stages: Phase 1 (Prepare): The coordinator sends a PREPARE message to all cohorts; each cohort executes the transaction locally up to the commit point, locks resources, writes to its WAL, and votes YES or NO. Phase 2 (Commit/Abort): If all cohorts vote YES, the coordinator writes a COMMIT record to its WAL and broadcasts COMMIT; if any cohort votes NO or times out, the coordinator broadcasts ABORT.

Key Architectural Rule / Formula:

Phase 1: Prepare & Vote (YES/NO). Phase 2: Commit (if all YES) or Abort (if any NO).

Engineering Trade-Offs

Trade-Off Dimensions & Analysis

Evaluating advantages and drawbacks during architecture interviews.

DimensionAdvantages (Pros)Drawbacks & Costs (Cons)
Atomicity vs AvailabilityGuarantees strict ACID atomicity across heterogeneous distributed databases.Blocking protocol: if the coordinator crashes during Phase 2, cohorts must hold locks indefinitely.
Performance & LatencyProvides strong immediate consistency without eventual consistency anomalies.High network roundtrips (4 messages per transaction) and lock contention drastically reduce throughput.
Interview Application

How to Frame Two-Phase Commit (2PC) in System Design Rounds

Senior-level talking points and related interview problems.

Interview Strategy

Evaluating in Loops

Evaluated in distributed transaction rounds, banking/financial systems, and microservices data consistency trade-offs (contrasting 2PC with Saga Orchestration).

Related Problems

Applied System Design Scenarios

  • Payment Gateway & Financial Ledger
  • Ride-Sharing Driver Matching
  • Distributed Database
Master distributed architecture

Practice system design with live interactive SVG canvases in ClawPad.

Download ClawPad