Consensus and Fault Tolerance
Consensus algorithms and Byzantine fault tolerance.
In distributed systems, many computers (called nodes) work together over a network. Consensus means all these nodes must agree on a single value or decision — even when things go wrong, like network delays or crashed machines.
Balance = 500
Balance = 400
please give me balance?
Imagine you and 4 friends are deciding where to eat dinner — over text. Everyone needs to agree on ONE place. Sounds easy, right? Now imagine some friends have no signal, some reply late, and one is secretly trolling. That's the consensus problem in distributed systems!
It means that a perfect consensus algorithm cannot exist if the system has: Asynchronous network Possibility of node failure
FLP Impossibility Theorem
Byzantine Generals Problem
The Byzantine Generals Problem describes a situation where distributed nodes must agree on a decision, but some nodes may behave maliciously or send incorrect information.
Story: Several generals are surrounding a city: -> If all generals attack together → they win. -> If some attack and some retreat → they lose. The Problem -> Generals communicate using messengers But some generals may be traitors. General A → Attack General B → Attack General C → Traitor Server A Server B Server C Server D
A → B : value = 10
A → C : value = 50
A → D : value = 10
Byzantine Fault Tolerance
Byzantine Fault Tolerance (BFT) is the ability of a distributed system to reach consensus even when some nodes behave maliciously, send incorrect messages, or act unpredictably.
| Faulty Nodes (f) | Required Nodes | | ---------------- | -------------- | | 1 faulty node | 4 nodes | | 2 faulty nodes | 7 nodes | | 3 faulty nodes | 10 nodes |
Rule: 3f + 1 nodes
To tolerate malicious nodes, the system relies on majority agreement among many nodes. Nodes exchange messages with each other and verify the majority decision. If one node sends wrong data, other nodes can detect the inconsistency.
Example: 4 nodes A,B,C,D A-> B = Attack A-> C = Retreat A-> D = Attack B-> C = Attack B-> D = Attack D-> B = Attack D-> C = Attack C-> D = Attack. (Reason 2Attack,1Retreat = Attack) C-> B = Attack -> consensus is achieved
Nodes compete to solve a computational puzzle, and the winner gets the right to add the next block.
Proof of Work (PoW)
Proof of Stake (PoS)
Nodes lock cryptocurrency as stake, and validators are selected to create the next block based on their stake.