Glossary · System coordination, integration and orchestration
Two-phase commit
Also known as: 2PC, Two-phase commit protocol
German: Zwei-Phasen-Commit
In distributed systems, two-phase commit (2PC) is an atomic commitment protocol in which a coordinator first asks all participants whether they can commit a transaction (prepare phase) and then, only if all agree, instructs them to commit, otherwise to abort (commit phase).
- System integration
In one sentence
Two-phase commit is a protocol in which a coordinator commits a distributed transaction only if all participants first confirm they can.
Example
An order booking uses two-phase commit so that the ERP database and the MES database either both record the order or neither does.
How it applies
- Engineering: 2PC gives atomicity across databases or resource managers that support it. Participants hold locks from the prepare phase until the decision, which reduces throughput and availability.
- Failure behavior: If the Transaction coordinator fails after participants have prepared, they remain blocked in doubt until it recovers. This blocking is the main weakness of 2PC.
- Architecture: Across independent services or companies, 2PC is rarely practical; the Saga pattern is the usual alternative.
- Documentation: Where 2PC is used, document the participants, timeouts and the manual resolution procedure for in-doubt transactions in the administration documentation.
Two-phase commit vs. saga
2PC provides all-or-nothing commit with locks held during the protocol. A saga executes local transactions one after another and undoes completed ones with compensating actions on failure, giving eventual rather than immediate consistency.