In this lesson, you will learn how to use majority-voting mechanisms to guarantee that a transaction is durably committed even when some nodes in a distributed database cluster fail or become unreachable.
The Problem: When Networks Split
In a distributed environment, you often replicate data across multiple nodes to ensure durability. If the network experiences a "partition" (where nodes can no longer talk to each other), you face a dilemma: do you wait for everyone to respond, or do you proceed and risk inconsistency? If you wait, you lose availability; if you don't wait, you might update a node that is isolated from the rest of the system.
The Solution: The Quorum
A "Quorum" solves this by requiring a majority vote before a transaction is considered committed. Instead of needing 100% agreement, the system requires a strict majority of nodes to acknowledge a write.
If you have N nodes, the size of the quorum is typically (N/2) + 1.
For example, if you have 5 nodes, you need at least 3 nodes to confirm a transaction.
- The coordinator sends the
COMMITrequest to all 5 nodes. - The nodes attempt to write the transaction to their logs.
- Once 3 nodes respond with "Success," the coordinator considers the transaction durably committed.
-- Conceptual logic of a Quorum Commit
IF (Nodes_Acknowledged >= (Total_Nodes / 2) + 1) THEN
RETURN "Transaction Committed";
ELSE
RETURN "Transaction Aborted (Insufficient Quorum)";
END IF;
Why This Works
The math behind quorum-based systems ensures that if a network partition occurs, only one side of the split can possibly reach a majority. The side that fails to achieve a quorum will automatically reject writes, preventing "split-brain" scenarios where two different versions of the data exist simultaneously.
By enforcing this majority rule, we ensure that as long as a majority of nodes are functional, our transaction logs remain consistent and durable. Even if a minority of nodes crashes or is disconnected, the surviving nodes hold the "truth" of the transaction, and the system remains reliable.
Key Takeaway: Quorum-based commit uses a strict majority of nodes to authorize transactions, ensuring durability and consistency in partitioned networks without requiring every single node to be online.