Two-Phase Commit
ELI5 — The Vibe Check
Two-phase commit (2PC) is like a wedding ceremony for distributed transactions. Phase 1: 'Do you all agree to commit?' Every node says yes or no. Phase 2: 'Then by the power vested in me, COMMIT.' If anyone says no in phase 1, everyone rolls back. It ensures all-or-nothing across multiple databases.
Real Talk
Two-Phase Commit (2PC) is a distributed transaction protocol ensuring atomicity across multiple nodes. A coordinator sends prepare requests to all participants, who vote commit or abort. If all vote commit, the coordinator sends commit; otherwise, it sends abort. The protocol can block if the coordinator fails between phases, leading to variants like 3PC and Paxos.
When You'll Hear This
"Two-phase commit guarantees atomicity but introduces a blocking window." / "We avoid 2PC in microservices and use saga patterns instead."
Related Terms
Consensus Algorithm
A consensus algorithm is how a group of servers democratically agree on something even when some of them are flaky or unreachable.
Distributed Database
A distributed database spreads your data across multiple computers that work together like a hive mind. If one server dies, the others pick up the slack.
Raft
Raft is a consensus algorithm designed to be understandable, unlike its predecessor Paxos which requires a PhD to read.
Strong Consistency
Strong consistency means the moment you write something, everyone everywhere immediately sees the updated value. No 'give it a sec' nonsense.