As discussed earlier, the distributed ledger gets updated only after a majority of the full nodes on a blockchain reach an agreement. When a transaction is announced by a user, all the nodes in the blockchain get intimation about it and the consensus mechanism (protocol or algorithm) provides the technique required by the nodes (machines or users) to coordinate their agreement on the state of the ledger. When the majority of nodes agree to the transaction, they let the transaction through and update the state of the ledger. This consensus protocol is at the core of a blockchain as it ensures that every block added to the chain carries authentic information about a transaction. There are several ways of implementing the consensus protocol. The most popular ones are -
Proof of Work (PoW)
This algorithm was implemented in Bitcoin to prevent double-spending. Double spending relates to the problem of spending the same money twice with two different people at the same time. PoW was a countermeasure to verify that the fund used in a transaction has not been spent elsewhere. It prevents duplication of funds in the digital environment.
The algorithm requires the miners to solve a cryptographic puzzle to be able to mine a block. The miner who solves the puzzle first gets to validate the block and gets a fee for doing the work. Solving the puzzle requires intensive computing power and those who can afford better systems have an advantage over others. This has resulted in bitcoin being mined more by certain pools making it less decentralized than perceived.
Proof of Stake
There is no work involved in this one, but the miner needs to own coins to be able to go ahead to mine or validate a block. So, the more coins a miner puts at stake, the more mining power they are likely to get. Ethereum 2.0 has planned to migrate its consensus protocol to PoS in the coming months.
The nodes lock in some of their Ether and participate in the validation process. The system rewards the validator with a fee proportional to the stake. This process was introduced to address the energy consumption and computing power required in PoW. However, PoS may not tick all the boxes as wealthier ones can stake more cryptocurrency and get more opportunities to validate while those with lesser balances may never get to mine a block. This may lead to some form of centralization of the system.
Delegated Proof of Stake
This is a variation of the PoS that is based on the voting system but the currency is still a direct consideration. The currency you own gets you a proportional number of votes to nominate a witness. This witness can validate the transaction and maintain it. They also get rewarded with a fee for doing the work.
The reward for these witnesses gets better as they rise through the rank in honesty. The top rankers in honesty get paid more creating a competition to be an honest witness. The fraudulent ones get replaced by others.
Proof of Importance
This one is like PoS as a bigger share in cryptocurrency gives them a higher probability to create blocks. Each node gets a combined score based on some variable and the stake. The score is directly proportional to their probability to create a block.
There are several other protocols like Proof of Assignment, Proof of Capacity, Proof of Elapsed Time, Proof of Identity, Proof of Authority, Proof of Activity. They have different approaches to achieve the same goal but none of them provides the most reliable method and each has its pros and cons.