Two-Phase Commit
Two-Phase Commit — An atomic commit protocol in which participants first prepare and then commit or roll back according to a coordinator decision.
Phase One: Prepare
The coordinator asks each participant whether it can commit. A participant that votes yes records enough durable state to remain capable of applying the final decision and enters a prepared state.
Phase Two: Decision
If all participants prepare successfully, the coordinator sends commit; otherwise it sends rollback. Participants apply the decision to their local transactions.
Failure Behavior
Two-phase commit addresses atomic commit but carries an availability cost. A participant that is prepared but cannot learn the final decision may need to hold resources while waiting. Coordinator and participant logs are therefore important for crash recovery.
2PC is not a consensus protocol, nor is it a free mechanism for making arbitrary distributed workflows atomic. Blocking and retained resources can reduce throughput.