The Blockchain Primer: Part 2 - How blockchain works?
Nivedan Rathi
Founder @Future & AI | 500k Subscribers | TEDx Speaker | IIT Bombay | AI Strategy & Training for Decision Makers in Top Companies | Building AI Agents for Sales, Marketing & Operations
In Part 1, we studied what blockchain is and why was there a need to develop such a technology. We will now have a peek at some of its inner workings. While the underlying technology is quite complex, I will however try my best to keep it light on tech and attend largely to the fundamental concepts. If you’re looking for something meatier than this, I would be happy to recommend some really good resources that will take you deeper into the details.
Let me make it clear from the very beginning. You don’t NEED TO learn how blockchain works in order to use products that are built on top of it. Just like the internet.
It is important to note that not all blockchains have the exact same underlying principles. There are numerous ways a blockchain can be designed in order to accurately serve its use-case. For the matter of this article, we’ll use the Bitcoin blockchain as a general reference to understanding how blockchains usually work.
A Chain of Blocks
First things first - what do the words ‘block’ and ‘chain’ in blockchain even mean? A good analogy to blocks in a chain is pages in a book. More technically, a block is nothing but a file that comprises of the below:
- The contents of the block. E.g., In Bitcoin, it includes transactions and the miner’s incentive. In other blockchains, it could contain any other data as well, usually information that signifies the transfer of value.
- A header which contains the data about the block itself. E.g., In Bitcoin, the header contains a reference to the previous block, a fingerprint (hash) of the data contained in this block and a timestamp among other things.
This hash is important for the ordering of blocks in a sequence, just like page numbers in a book. However, one significant difference to know is that unlike page numbers, these hashes are dependent on the contents of the blocks themselves. This ensures that if someone tampers with some of the transactions in a historical block, its hash would change and it would not fit in the right sequence when other nodes see that block. We’ll see later in this article, how making the process of creating the hash of a block slow (mining) makes blockchains protected against the baddies.
Distributed Storage Network
In the Bitcoin blockchain, every time someone wishes to send bitcoins to a friend, they broadcast it to the entire network instead of just sending it as an individual message to the friend. This empowers each node in the network to keep a record of all transactions made by everyone at all times while also having the ability to validate every transaction against the entire history of transactions from each account. Having a public ledger eliminates the need to depend on a central server to authenticate and validate every transaction.
This is how Blockchain solves the problem of centralization. By making everyone the owner of the data. No more risk of a single point of attack. No more one human gone crazy, taking over the network.
Mining
‘Mining’ is a process in which participating nodes add a new block of valid transactions to the blockchain upon successfully solving a mathematical puzzle (recall block fingerprint/hash). The solution to the puzzle is called Proof of Work and it requires spending huge amounts of computational resources (& electricity) to generate it. Hence, miners are incentivized for mining each block. Since doing this is a slow process for an individual node, if someone wants to rewrite parts of the blockchain with a malicious intent, it will take them a very long time to overtake the rest of the honest network combined. The concepts of mining and proof of work are at the core of why blockchains have a ‘tamper-proof’ and ‘immutable’ reputation.
Consensus
In blockchain, it is possible for multiple nodes to generate conflicting but valid updates (mined blocks) to the ledger at roughly the same time. For instance, it is quite common in the Bitcoin blockchain for more than one nodes to guess the proof of work for the latest block simultaneously. Since blocks take time to be shared across the network, different nodes may receive different blocks at the same time. When this happens, which one should be considered legit by all nodes?
To solve this problem, the Bitcoin blockchain adopts the ‘longest chain rule’.
‘Longest chain rule’ is the protocol that resolves any conflicts of data replication and ensures that the entire network stays in a state of consensus on the latest state of the ledger. It is designed to ensure it’s in the best interest of each node to mine on top of the latest block added to the network and increase their odds of winning the race for the proof of work on the next block before everybody else and subsequently, grab the incentive.
By aligning miner incentives with the honest operation of the network - replicating the entire blockchain and achieving consensus across the network, blockchain makes it astronomically hard for the hackers to tamper with the data. The blockchain ecosystem puts all of these concepts together in a wonderfully concerted manner to make what was previously impossible, possible.
Winding up
Now, there are some advanced ideas introduced in this post. These are mainly useful to understand blockchain in the context of Bitcoin. Not all blockchains need Bitcoin mechanisms such as proof of work, mining, longest chain rule etc. Bitcoin was the first attempt at maintaining a decentralized, public ledger with no formal control or governance. With a coordinated global effort, this field is under radical evolution and a lot of new developments in blockchain technology can be seen popping up in the news all the time.
Hope this high-level view of how the Bitcoin blockchain works was useful. Once again, hit me up if you’re looking for resources to dive deeper.
See you in the next one!