Atomic Across Shards
When a transaction touches rows on several shards, all of them must commit or none of them. Two phase commit (2PC) is the classic protocol that achieves this atomicity across nodes.
The Two Phases
- Prepare phase: the coordinator asks every participant if it can commit. Each writes its changes durably and votes yes or no.
- Commit phase: if all voted yes, the coordinator records a commit decision and tells everyone to finalize. If any voted no, it tells everyone to abort.
Once a participant votes yes it is bound: it must be able to commit even after a crash, so it logs the prepared state.
The Blocking Weakness
If the coordinator crashes after participants vote yes but before they learn the decision, those participants are stuck holding locks until it recovers. This blocking behavior is why distributed SQL systems replicate the coordinator state with Raft so the decision survives failures.
Key idea
Two phase commit guarantees atomicity across shards by voting then committing, but its blocking on coordinator failure pushes modern systems to replicate the coordinator.