Course contentsShow
← System Design
Lesson 577 of 1,91916. Distributed TransactionsFree lesson

2PC vs Single-Node Transactions

Comparing coordination overhead, failure modes, and performance tradeoffs.

2PC vs Single-Node Transactions

What you'll learn: How two-phase commit differs from traditional single-node transactions in coordination overhead, failure handling, and performance.

The Core Difference

A single-node transaction executes entirely on one database server. It uses local locks, writes to a local log, and commits or aborts in milliseconds. There's no network communication—just memory and disk operations on a single machine.

Two-phase commit (2PC) distributes the transaction across multiple nodes. It requires a coordinator to orchestrate prepare and commit phases, network round-trips to each participant, and synchronized logging across all nodes.

Coordination Overhead

Single-node transactions have zero coordination overhead. The database engine simply locks rows, updates them, and writes one commit record.

2PC adds significant coordination: the coordinator must send prepare messages, wait for all participants to respond, send commit messages, and wait again. Each network hop adds latency—typically 10-100x slower than local operations.

Failure Modes

When a single-node database crashes mid-transaction, recovery is straightforward: replay the local log. Either the commit record exists (transaction completed) or it doesn't (roll back).

2PC has complex failure scenarios: what if the coordinator crashes after some participants commit? What if a participant crashes during prepare? The blocking problem (from previous lessons) means nodes may wait indefinitely. Recovery requires persistent logs on all nodes and timeout protocols.

Performance Trade-offs

Single-node transactions scale vertically and deliver high throughput (thousands per second). They're limited by one machine's resources but have predictable, low latency.

2PC sacrifices throughput for distributed atomicity. Each transaction involves multiple network round-trips, holds locks across nodes longer, and becomes slower as more participants join. You gain cross-node consistency but lose 50-90% of transaction throughput.

Key Takeaway: Single-node transactions are fast and simple but limited to one machine; 2PC enables distributed atomicity at the cost of coordination overhead, complex failure handling, and significantly reduced performance.