Blockchain Data Management
Learn more about data management with blockchain.
Join the DZone community and get the full member experience.Join For Free
In my last blog, I provided a brief on the basics of blockchain. In this blog, I will try to further explore how the actual data gets stored/managed on a chain of blocks.
As you all know, a blockchain is a distributed architecture that follows a peer-to-peer network and essentially inherits all of the advantages of a peer-to-peer network, like performance, avoiding a single-point failure, etc.
Below, the diagram shows a high-level overview of a peer-to-peer network. Here, each and every node is connected with each other and shares resources, so there is no dependency on a centralized machine, like a traditional client-server architecture.
Data Management on a Chain
Here, we will try to understand how data gets managed on a blockchain as well as the contents of the individual block on each blockchain.
In the above image, there are blocks with actual transaction data on it. Apart from the transaction data, there are a few other standard properties on every block, which are as follows:
1. Index: Index is nothing but a sequential block number
2. Timestamp: Time on which block the data is added
3. Hash: this is a unique hash value for the data. It is generated using mathematical functions. Every block has a different hash value, which directly communicates with the data (i.e. if the data gets changed, then the hash value also gets changed)
4. Previous Hash: It contains a hash value of the previous block, which is to get a backward reference
In my previous blog, I had mentioned that blockchains’ key trait is immutability. Let see how it works.
Immutability Via Blockchain
We know that all of the traditional databases are built for CRUD (Create, Read, Update, and Delete) operations. On the other hand, blockchain only allows appending and retrieving, so once added, data cannot be deleted and updated.
In a blockchain, any node has access to a ledger and can check and verify if the ledger has been tampered with or if any transaction in any block has been changed. This is mainly done by calculating the hash value of the block data and then comparing it with the previous hash value stored in the next block.
Below is an example that will help us to understand it more…
Here, the peer or node can calculate the hash value of block#554 and can check if the previous hash value of block#555 is the same as the hash value of block#554. If they are not the same, then it is declared as tampered. The following image depicts the verification flow. In the case of tampered data and failure of validation, rejection of a block will happen by all the nodes.
Because of this, blockchain leverages consensus (general agreement) mechanism for validating the transactions. We will talk about this more in the section below.
It’s a protocol by which the peer agrees with the state of the ledger, it ensures all peers the in the network have exactly the same copy of the ledger, and that fraudulent transactions are kept out of the ledger. It also guarantees to record the transaction in chronological order.
Below is a brief explanation of the common consensus protocols.
Common Consensus Protocols:
1. Proof of Work:
Proof of Work (PoW), as the name states, it is the validation of the work that happened and proving that it is correct. This is the way we use a consensus to make sure the authenticity of the chain is good.
The main drawback of using PoW is that it requires more electric power and high-computing hardware, which can be expensive.
Additionally, Bitcoin and Ethereum blockchain networks use Proof of Work.
2. Proof of Stake:
Proof of Stake (PoS) is an alternate way of verifying and validating the transaction or block. PoS picks the validator by the amount of stake the validator has and the respective age of the stake. In PoS, the validators earn the part or whole of the transaction fee.
PoS also eliminates the main challenges from PoW and is believed to have an advantage as there is no need of expensive hardware and also energy efficient as it won’t consume as high of electricity as PoW does.
The Tendermint is an open-source project to address the speed, scalability, and environmental issues of Bitcoin’s Proof-of-Work consensus algorithm. It uses the BFT (Byzantine fault-tolerant consensus) algorithm.
Published at DZone with permission of Prashant Gurav. See the original article here.
Opinions expressed by DZone contributors are their own.