System Design (50 Qs)•Part 3: Distributed Transactions, Consensus & Reliability (26 - 36)
Distributed Consensus: Raft vs Paxos.
In Simple Words: Distributed consensus algorithms ensure that a cluster of servers agree on a shared state machine log, even if some nodes crash or experience network partitions.
- Paxos: The original consensus algorithm proven by Leslie Lamport. Renowned for mathematical elegance but notoriously difficult to understand and implement in real software.
- Raft: Designed specifically to be understandable while providing equivalent safety to Multi-Paxos.
- Divided into 3 explicit subproblems: Leader Election, Log Replication, and Safety.
Architecture Flowchart
stateDiagram-v2
[*] --> Follower
Follower --> Candidate: Election Timeout
Candidate --> Leader: Votes from Majority (> N/2)
Candidate --> Follower: Discovers Leader with higher term
Leader --> Follower: Discovers higher term node