Two-phase commit (2PC) is a protocol that lets a single transaction span several databases or machines while still being atomic - either all of the participants commit their part or all of them abort. One node acts as the coordinator and the others as participants. It is the standard way to keep multiple independent systems agreeing on the outcome of one logical transaction.
As the name says, the protocol runs in two phases. In the prepare phase, the coordinator asks every participant whether it can commit; each participant does the work, makes it durable so it could commit if asked, and votes yes or no. In the commit phase, if every participant voted yes the coordinator tells them all to commit, and if any voted no it tells them all to abort. Because every participant has promised in advance that it can commit, the final decision can be carried out reliably.
Jim Gray’s 1981 “Transaction Concept” paper discusses two-phase commit as part of extending the transaction abstraction across multiple resources, and the protocol is a firsthand topic in his later transaction-processing work. The same reasoning that makes a single-node commit atomic - prepare durably, then decide - is lifted to a group of cooperating nodes.
Two-phase commit is famously a blocking protocol: if the coordinator fails after participants have voted but before they learn the decision, those participants can be stuck holding resources, unable to safely commit or abort until the coordinator recovers. This weakness motivated later work on three-phase commit and on consensus-based approaches, but 2PC remains the foundational protocol for distributed atomic commit.