Two-phase commit
Two-phase commit is a distributed transaction protocol in which a coordinator first prepares participants and then directs them to commit or abort the transaction as a group.
Microservices Patterns, Second Edition
Two-phase commit is a distributed transaction protocol that coordinates participants through a prepare phase and a commit or rollback phase.
- How it is used
- Coordinates transactions for system operations that span multiple services.
- How deep it goes
- Defines the protocol’s role and trade-offs, but does not detail its phase mechanics.
- Examples
- Uses order creation across Order and Consumer services, including customer credit reservation, to illustrate distributed transaction boundaries.
- What you can do after
- Evaluate classic distributed transactions against Saga for commands spanning microservices.
Read how Microservices Patterns, Second Edition explains two-phase commit →
Think Distributed Systems
A distributed transaction commit protocol that coordinates commitment in two phases among participating processes.
- How it is used
- Coordinates unanimous commit or abort decisions across resource managers in distributed transactions.
- How deep it goes
- Explains roles, phases, persistent logs, recovery actions, and failure blocking, while stopping short of implementation code.
- Examples
- Uses coordinator and resource-manager message flows, persistent log records, recovery actions, and a coordinator-failure scenario.
- What you can do after
- Evaluate atomic commit behavior and diagnose why coordinator failure can block participants.
Read how Think Distributed Systems explains two-phase commit →
PostgreSQL Mistakes and How to Avoid Them
Two-phase commit is a distributed transaction protocol in which participants first prepare to commit and then commit or abort based on a coordinator decision.
- How it is used
- Coordinates application-level atomicity when one transaction spans multiple PostgreSQL database nodes.
- How deep it goes
- Defines the prepare-and-decision protocol and operational hazards, but does not provide a complete implementation procedure.
- Examples
- Uses alpha and beta account updates, PostgreSQL account fixtures, and a lost-money versus unexpected-gift scenario.
- What you can do after
- Evaluate cross-node atomicity failures and judge when prepared transactions’ locking and recovery costs outweigh their benefits.
Read how PostgreSQL Mistakes and How to Avoid Them explains two-phase commit →
Kafka for Architects
Two-phase commit is a distributed transaction protocol in which a coordinator first prepares all participants and then directs them to commit or abort as a group.
- How it is used
- Coordinates atomic outcomes across independent systems when distributed operations must either all succeed or all fail.
- How deep it goes
- Defines prepare, commit, and abort steps, then stops at Kafka’s lack of current 2PC support and the outbox workaround.
- Examples
- Uses a profile database update paired with a Kafka notification to expose dual-write inconsistency.
- What you can do after
- Evaluate when transactional outbox is preferable to direct cross-system writes involving Kafka.
Amazon Web Services in Action, Third Edition: An in-depth guide to AWS
Two-phase commit is a distributed transaction protocol that first obtains participant decisions and then instructs all participants to commit if every participant agrees.
- How it is used
- Explains why horizontally scaling relational databases becomes difficult when transactional guarantees require coordination among nodes.
- How deep it goes
- Traces a simplified two-node protocol from query request through unanimous decision and final commit, then stops at scaling overhead.
- Examples
- Uses a two-node INSERT, UPDATE, or DELETE transaction coordinated through participant checks and a final commit.
- What you can do after
- Evaluate the coordination cost that transactional guarantees impose when adding nodes to a relational database cluster.
Also covered in
What to know first
- ACIDACID is the set of database transaction properties—atomicity, consistency, isolation, and durability—that characterize reliable transactional behavior.
- atomicityAtomicity is the property that an operation or group of operations takes effect as an indivisible whole, without observable partial effects.
- microservice architectureMicroservice architecture is a software architectural style that structures an application as independently deployable services, typically organized around focused capabilities and communicating through defined interfaces.
Related concepts
- sagaalternative to · A saga is a distributed transaction pattern that coordinates a sequence of local transactions and uses compensating actions to address failures.
- ACIDused by · ACID is the set of database transaction properties—atomicity, consistency, isolation, and durability—that characterize reliable transactional behavior.
- Apache Kafkacontrasts with · Apache Kafka is a distributed event-streaming platform for publishing, storing, and processing streams of records.
- atomicitykind of · Atomicity is the property that an operation or group of operations takes effect as an indivisible whole, without observable partial effects.
Questions about two-phase commit
What is two-phase commit?
Two-phase commit is a distributed transaction protocol in which a coordinator first prepares participants and then directs them to commit or abort the transaction as a group.
Which Manning books explain two-phase commit?
Microservices Patterns, Second Edition, Think Distributed Systems, PostgreSQL Mistakes and How to Avoid Them, Kafka for Architects and Amazon Web Services in Action, Third Edition: An in-depth guide to AWS.
What should I know before learning two-phase commit?
Manning books that teach two-phase commit usually introduce ACID, atomicity and microservice architecture first.
What is the difference between two-phase commit and saga?
Two-phase commit is a distributed transaction protocol in which a coordinator first prepares participants and then directs them to commit or abort the transaction as a group. A saga is a distributed transaction pattern that coordinates a sequence of local transactions and uses compensating actions to address failures.
What is two-phase commit a kind of?
Two-phase commit is a kind of atomicity. Atomicity is the property that an operation or group of operations takes effect as an indivisible whole, without observable partial effects.
What is two-phase commit also called?
Two-phase commit is also called 2PC.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.




