NEW
Also known as: 2PC, Distributed Commit
Two-Phase Commit is a distributed protocol that coordinates participants to atomically commit or abort a transaction across multiple systems.
DESCRIPTION
2PC ensures all participants in a distributed transaction either commit or roll back together, preserving atomicity. It proceeds with a prepare phase for voting and a commit phase for finalization. While conceptually simple, 2PC can block if a coordinator fails and introduces latency. It suits tightly coupled systems needing strong consistency. Alternatives like sagas or idempotent retries often fit microservices with lower coordination requirements.
ALTERNATIVE DEFINITIONS
Wikipedia
The two-phase commit protocol (2PC) is a type of atomic commitment protocol that ensures in a distributed system all the nodes in an atomic transaction either commit or abort consistently.
Highlights atomic commitment across distributed nodes.
Microsoft Learn
The two-phase commit protocol (2PC) is a standard protocol for coordinating the commit or rollback of a distributed transaction across all resource managers enlisted in the transaction.
Explains coordination across resource managers in enterprise stacks.
RELATED TERMS
Distributed Transactions ACID Atomicity Coordinator XA Consensus Idempotency Rollback
COMPETING TERMS
Saga Pattern Three-Phase Commit
RELATIONS
- Broader: Commit
KNOWLEDGE AREAS
Data Storage & Operations Data Integration & Interoperability Software Engineering Infrastructure
TARGET AUDIENCE
Software Developer Data Engineer DevOps Engineer Cloud Architect
EXTERNAL SOURCES
- Wikipedia - Two-phase commit protocol
- PostgreSQL - 2PC feature in PostgreSQL
- Microsoft - 2PC in distributed transactions
- The Open Group (X/Open XA) - XA distributed transaction standard
TOP QUESTIONS
When should I use Two-Phase Commit?
Use 2PC when you need strong atomicity across multiple resource managers and can tolerate blocking and coordination overheads.
Category: Opinion
What are the main drawbacks of Two-Phase Commit?
Coordinator failures can block progress, and network partitions cause delays. It adds latency and complexity.
Category: Risks
How does Two-Phase Commit work?
Participants vote to prepare in phase one; if all agree, the coordinator instructs commit in phase two, otherwise abort.
Category: Example
What’s a common alternative to Two-Phase Commit in microservices?
The Saga pattern orchestrates a sequence of local transactions with compensations, trading strict atomicity for availability.
Category: Alternatives
Is Two-Phase Commit fault-tolerant?
It tolerates some failures but can block if the coordinator is unavailable. Protocols like three-phase commit reduce blocking at additional cost.
Category: Misunderstanding
Does Two-Phase Commit guarantee consistency?
It guarantees atomic commit/abort across participants, contributing to consistency under ACID, but does not solve all consistency anomalies.
Category: Relevancy
How do logs help in Two-Phase Commit?
Participants and coordinators use write-ahead logs to recover decisions after failures, ensuring durability.
Category: Requirements
What’s the role of XA in Two-Phase Commit?
XA defines a standard for coordinating distributed transactions across heterogeneous resource managers implementing 2PC.
Category: Example
Can Two-Phase Commit scale to high-throughput systems?
It can, but coordination overhead limits scalability. Batch commits, sharding, and alternatives may provide better throughput.
Category: Opinion