Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

blockchain
consensus
algorithm

What is a consensus algorithm in blockchain?

Ahsan Amin

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

What are concensus algorithms?

Consensus algorithms are procedures through which all nodes in a network reach a common agreement about the current state of the distributed ledger.

Blockchain is a decentralized network maintained by a network of nodes (miners or validators). Every node has its own copy of the blockchain and to maintain the same state of the blockchain across the network we need a consensus mechanism. The general working of a consensus algorithm is shown below.

Consensus algorithms
1 of 7

Purpose of consensus algorithms

  • Security: Every node verifies all the transactions in a block before adding them to their journal. It prevents malicious nodes from adding malicious transactions to the network.
  • Accountability: The stake of a node is slashed if they attempt to add a malicious transaction to the network if the blockchain is using a proof of stake algorithm. On the other hand, if blockchain uses a proof of work algorithm, it will lose a lot of energy as other nodes will eventually reject its block. The transaction will never become part of the blockchain.

Types of consensus algorithms

  • Proof of work: Every miner has to solve a complex mathematical puzzle that requires a lot of computational power to be able to mine the next block. Upon successful mining of the block, the miner gets a reward in the blockchain's local currency, for example, Ether in the case of the Ethereum blockchain.
  • Proof of stake: Validators lock some of their coins in the network as stake, and if a validator's block is added to the blockchain, they will get a reward, and their stake will increase.
  • Proof of elapsed time: Every node has to wait for a random amount of time and include their proof wait in their block to be able to mine a block.
  • Proof of burn: Validators burn coins to be able to mine the next block. The more coins they burn, the greater the chances of being selected to mine the next block.

RELATED TAGS

blockchain
consensus
algorithm

CONTRIBUTOR

Ahsan Amin
Copyright ©2022 Educative, Inc. All rights reserved

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring