In this article, we learn about the five major layers (hardware, data, network, consensus, and application) that make up a blockchain.
Table of contents.
- Hardware Layer.
- Data Layer.
- Network Layer.
- Consensus Layer.
- Application Layer.
Blockchain technology is a form of record-keeping whereby it is almost impossible to cheat, hack or mutate the system without notice.
A blockchain is a digital ledger and in most cases, it is distributed across many peers to ensure it is tamper-proof. Blockchains have many applications from financial markets to insurance to supply chain management. In cryptocurrency blockchains, each block in the chain stores transactions from participants, and as the number of blocks increases, so as the security of the chain because current blocks use the genesis block - the first block in the chain, as a root of trust.
Blockchain technology has gained popularity due to its various properties such as programmability, distribution, immutability, unanimous, and security among others. In past years various programmers tried to create digital money but always failed because, if someone creates a currency, what is to prevent him/her from assigning himself/herself huge amounts of the currency? Blockchain solved this because, unlike the previous attempts whereby the database was centralized blockchain proposed a solution whereby people run their local databases which agreed with others in the network, so if a person were to assign themselves huge amounts of currency, it would have to be reflected on the rest of the peers. In addition to this, blockchain also has a consensus mechanism that verifies that person X worked for the amount they own.
Blockchain technology eliminates intermediaries such as financial institutions, lowers the cost of transacting, it is transparent and secure. Blockchains also allow anyone to join and participate in them because there is no centralized gatekeeping. This means that the blockchain networks need to be able to scale and so layers were introduced as a requirement for scalability. In this article, we look at the five major layers that blockchain is built with.
The following image summarizes the layered architecture of a blockchain;
We have a client-server architecture where clients which include desktop apps, and mobile or web apps request data from a server that is physically located in a data center. For example, google drive stores and retrieves data from google servers distributed across the globe.
Blockchains introduced a peer-to-peer network where instead of storing data in google servers, anyone could take up this responsibility of data storage and maintenance and be rewarded for their contributions.
In blockchains, these people who took up the responsibility of storing the distributed database, processing transactions, and maintaining the database are referred to as miners. Miners have nodes that make up the network. A node could be a full node that stores the full copy of the blockchain or a light node that stores a portion of the database. Nodes come in different types for different purposes. These are what make up the hardware layer of any blockchain.
The following shows an ASIC Bitcoin miner, this is one of the hardware components that make up the Bitcoin protocol;
A blockchain(chain of blocks) is a data structure such as a linked list and just like a linked list it has pointers that point to previous and next blocks. In other words, we have a block of transactions that have been validated, this block has a max limit of transactions it can hold, once full the next block starts to form. The first block is referred to as the genesis block, it has no predecessor but points to the next forming block.
Within each block, there is another data structure referred to as the Merkle tree which is a binary tree of hashes. Each block has a root hash which is a combination of all transaction hashes in the block. The Merkle tree is what prevents transactions from being mutated because if they are the hash changes. Hashing produces a fixed-length string that is unique for any input meaning if even a single character in a transaction changes, the hash is bound to change making the transaction invalid. If the transaction is invalid, so is the block. If a block is invalid it is rejected by other nodes and it is not part of the chain.
The Merkle tree is responsible for providing security, integrity, and irrefutability of the blockchain.
Digital signatures created by strong cryptographic algorithms are also used to prevent transaction mutation. A private key signs a transaction and anyone with the corresponding public key can verify the signature.
The network layer also referred to as a peer-to-peer layer allows communication between the nodes we discussed earlier. This layer is comprised of peers. According to the dictionary, a peer is one that is of equal standing with another and as such in a peer-to-peer network every peer in the network has equal power and responsibilities.
This layer transmits data packets(transactions) between nodes and ensures that nodes can find each other during discovery. The network load is distributed between every peer equally. Once a node validates a block it propagates it to other nodes for the same validation.
The following image shows the difference between a peer-to-peer network and a centralized network;
This is one of the most critical aspects of any blockchain. A consensus mechanism is a fault-tolerant system used in a blockchain network to assist peers in agreeing on a single data value or network state. For example, peers could agree that X amounts of Bitcoins belong to person A.
A consensus layer establishes a clear set of rules in the network. These rules are adhered to by all participants. These rules are set by the majority of the participants(95%), they make sure power remains decentralized and distributed.
This layer also ensures that the blockchain is led by a single source of truth and when disputes occur that result in chain splits, they are resolved and the single-chain continues.
This layer is responsible for block validation, block ordering, and making sure that all peers agree by using different types of consensus mechanisms such as Proof of Work(PoW), Proof of Elapsed Time(PoET), Proof of Authority(PoA), Proof of Capacity(PoC), Proof of Burn(PoB) among others.
This layer consists of code that handles the business logic of the blockchain such as smart contracts, and chain code. It comprises applications with user interfaces that users use to communicate with the network. These could be Dapps(Decentralized Applications), wallets, and APIs among others.
Remember the client-server architecture, In this case, the peer-to-peer decentralized network is the backend server and this layer acts as the frontend where apps with interfaces are built to communicate with the distributed ledger.
Transactions move from this layer to the execution layer. Applications communicate with the execution layer which in turn executes code on the blockchain.
The blockchain hardware layer allows anyone to take up the responsibility of data storage and maintenance. This layer is comprised of mining rigs.
A block is comprised of transactions that are stored using a Merkle tree. The leaves of the Merkle tree consist of transaction hashes.
Blockchains commonly use a peer-to-peer network structure where all nodes have equal authority.
A consensus mechanism is a fault-tolerant system used in a blockchain network to assist peers in agreeing on a single data value or network state.
The application layer consists of code that handles the business logic of the blockchain such as smart contracts, and chain code. This code is the frontend while the blockchain is the backend.