What is consensus?
A consensus is a general agreement. An example would be a group of people going to the cinema. Whenever there is no disagreement about a film choice, a consensus is reached. If there is disagreement, the group must have the means to decide which film to see. There is a possibility that the group will eventually split in extreme cases.
Ethereum's blockchain is formalized, and reaching consensus is defined as at least 66% of network nodes agreeing on the global state.
What is consensus mechanism?
As a whole, consensus mechanisms refer to the protocols, incentives, and ideas that allow a network of nodes to agree on the state of a blockchain.
Ethereum uses a proof-of-stake-based consensus mechanism that derives its crypto-economic security from a set of rewards and penalties applied to capital locked by stakers. It creates an extremely high cost to attack the Bitcoin network and encourages stakeholder to operate honest validators.
Then, there is a protocol that governs how honest validators are selected to propose or validate blocks, process transactions and vote for their view of the head of the chain. In the rare situations where multiple blocks are in the same position near the head of the chain, there is a fork-choice mechanism that selects blocks that make up the 'heaviest' chain, measured by the number of validators that voted for the blocks weighted by their staked ether balance.
To achieve consensus, some concepts are not explicitly outlined in code, such as out-of-band social coordination as a last line of defense against network attacks.
These components together form the consensus mechanism.
TYPES OF CONSENSUS MECHANISMS
Like Bitcoin, Ethereum once used a proof-of-work (PoW) based consensus protocol.
The validation process creates blocks. For each slot, a validator is randomly selected to propose the block. 'Execution payloads' are requested from both consensus and execution clients. They wrap this in consensus data to form a block, which they send to other nodes on the Ethereum network. This block production is rewarded in ETH. In rare cases when multiple possible blocks exist for a single slot, or nodes hear about blocks at different times, the fork choice algorithm picks the block that forms the chain with the greatest weight of attestations (where weight is the number of validators attesting scaled by their ETH balance).
The network is secure due to the fact that it would require 51% of the network's computing power to create a fraudulent chain. This would require such huge investments in equipment and energy; you're likely to spend more than you'd gain.
Ethereum uses a proof-of-stake (PoS)-based consensus algorithm.
Proof-of-stake is done by validators who have staked ETH to participate in the system. A validator is chosen at random to create new blocks, share them with the network and earn rewards. Instead of needing to do intense computational work, you simply need to have staked your ETH in the network. This is what incentivises healthy network behaviour.
A proof-of-stake system is crypto-economically secure because an attacker trying to control the chain must destroy a massive amount of ETH. A system of rewards incentivizes individual stakers to behave honestly, and penalties disincentivize stakers from acting maliciously.