# Consensus Problem of Distributed Systems

• Last Updated : 26 Nov, 2021

Consensus is a general agreement on a decision made by the majority of those involved. For example, the problem may be as simple as friends trying to decide which restaurant has multiple options to choose from or complex as decisions on distributed systems.

## Need of consensus in a distributed system:

In a distributed system, nodes are distributed across the network. Some of these nodes might get failed(crash fault) or starts behaving abnormally (Byzantine Fault). In such a scenario, it becomes difficult to come to a common decision. More concisely,

• There are n processes, m of which may be faulty.
• The task is to make all the Nonfaulty processes agree on some value(s) even in the presence of the faulty processes.

So we can remove these problems by given below solutions:

• Consensus Without Any Fault
• Consensus With at most m Crash Faults
• Consensus With at most m Byzantine Faults

## Consensus Without Any Fault:

### State of Network:

• Reliable communication medium
• Synchronous system
• Fully connected
• The receiver always knows the identity of the sender of a message

### Steps:

• Each process will broadcast its value to all other nodes.
• Every node will agree on the minimum of all the values they receive
• Since there is no fault, everyone will receive the same set of values and their minimum will be the same.

## Consensus With at most m Crash Faults:

### State of Network:

• Reliable communication medium
• Synchronous system
• Fully connected
• The receiver always knows the identity of the sender of a message

### Steps:

• At least m+1 rounds are needed to come to a consensus in such an environment.
• In 1st round broadcast your own value, and from successive rounds broadcast any new value that the node has received in the last round.
• Failure of a node may occur in between when it is sharing values with the other nodes. So if at most m nodes might get failed then in worst-case scenario one node failed every time when we are trying to achieve a consensus.
• And if every node goes through m+1 rounds then we are sure that out of these m+1 there will surely be at least one round when no node has failed and everyone gets every value.
• So after m+1 rounds, every node will select the minimum.

## Consensus With at most m Byzantine Faults:

Byzantine Faults: In simple terms, a Byzantine Fault is where some nodes start behaving maliciously or abnormally. Here problem is that any such node may send two different value to two different nodes and if so happen then all our previous methods won’t work. Because previously we are sure that if a node sends a value then it will send the same value to every node.

### State of Network:

• Reliable communication medium
• Synchronous system
• Fully connected
• The receiver always knows the identity of the sender of a message
• S is the set of all the nodes.
• The node who initiates the agreement protocol is the commander
• The value suggested by the commander is the order
• The other nodes, to whom the commander sends the order, are his lieutenants.
• OM stands for Oral Message and this term is just to show that one node can tell two different values to two different nodes.

### Steps:

• We will show here a recursive algorithm called Lamport-Shostak-Pease Algorithm to solve the Byzantine General Problem.
• Base Case- OM(0,S) :
• The commander i sends the proposed value v to every lieutenant j in S – {i}
• Each lieutenant j accepts the value v from i
• Recursive Case- OM(m,S):
• The commander i sends a value v to every lieutenant j ∈ S – {i}.
• Let vj be the value lieutenant j receives from the commander i, ( 0 if receives no value).
• Lieutenant j now initiates OM(m-1, S – {i}) with value vj, as a commander. At the end of each of these recursive executions, every loyal lieutenant j ∈ S – {i} has agreed on a set of pairs (k,vk), one for each k ∈ S – {i}.
• After Step 3 has been completed by all lieutenants, each lieutenant j collects the pairs it received in Step 3 (its own pair containing the original value from its commander and the other pairs containing the values returned by its own lieutenants by the recursive invocation of OM(m,S-{i}) )
• The each lieutenant j agrees on the value v = majority ( { (k,vk) | k ∈ S -{i} } ) that is in the majority of those pairs.

Here,

• All the solutions discussed till now are possible when the system is synchronous, completely connected and nodes know the identity of each other.
• In the Byzantine Faults case, no solution is possible if n < (3m + 1).
• In the asynchronous model, the consensus is impossible to achieve even with a single crash failure.
• Consensus is impossible to achieve even with a single link failure, even in the synchronous model.

There are some more Consensus Algorithms for Permissioned Environments like RAFT, PAXOS. Apart from the above discussion, there are some more Consensus Algorithms that are used in Permissionless Environment, like Proof of Work: It is used in Bitcoin.

My Personal Notes arrow_drop_up