Distributed Transactions and Consensus
Consensus: Getting several nodes to agree on something.
The Requirements of Consensus
- Agreement: No two nodes decide differently.
- Integrity: No node decides twice.
- Validity: If a node decides value V, then V was proposed by some node.
- Termination: Every node that does not crash eventually decides something. (This is the hard part in an unreliable network).
Epoch Numbers and Quorums
In consensus protocols (Paxos, Raft, Zab), we use Epoch Numbers (or viewstamped numbers) to identify the current leader.
- If a leader is suspected dead, a new election starts with a higher epoch number.
- If a node with an old epoch number tries to make a decision, it is ignored.
- For any decision to be made, the leader must collect votes from a Quorum of nodes.
Total Order Broadcast
Consensus is essentially about Ordering. If you can agree on the order of a log of messages, you have consensus.
- Zookeeper and etcd use consensus to maintain a small amount of highly consistent data (configuration, locks, membership).
Knowledge Check
What happens if a leader from an old 'Epoch' tries to commit a value?
It is automatically accepted.
It is rejected because the quorum has already moved to a higher epoch.
The network shuts down.