Introduction To Blockchain As A Train
Tags: longform, blockchain, aws
Published: 2021-08-09 04:18:34

This post is excerpt from my ebook "[Introduction To Blockchain](https://www.amazon.com.au/Introduction-Blockchain-Whats-fuss-about-ebook/dp/B07MG8Z99R)". This is the first in a series of Blockchain articles. In the subsequent articles, I will cover the topics of Types of Blockchains, Blockchain Consensus, Use Cases, Blockchain Testing, Testing Challenges, and [Blockchain on AWS](https://aws.amazon.com/blockchain).

Don't worry if you are wondering how does the train picture relates to Blockchain. All will be clear when you read the post.

People use the term 'Blockchain Technology' to mean different things and it can be confusing. Sometimes they are talking about The Bitcoin, sometimes its smart contracts and sometimes it’s other virtual currencies. Irrespective of intention or confusion, they are all talking about distributed ledgers.

Blockchain is nothing more than a distributed ledger. It is a digital ledger for storing data that is constantly growing as new sets ‘blocks’, are added to it. The most famous implementation of this technology is the cryptocurrency called Bitcoin.

Before we dig deep into the components that make up the Blockchain, we first need to go back down memory lane and learn about the Blockchain's origin and history.

### History and Origin
In wake of the GFC, Satoshi Nakamoto (or an unknown group of people) in 2008 conceptualized the first Blockchain which was published as a white-paper titled “[Bitcoin: A Peer to Peer Electronic Cash System](https://bitcoin.org/bitcoin.pdf)”. The main aim of the paper was to build a peer to peer version of digital currency that would enable people to spend it directly without going through a financial institution. It was a huge innovation that enabled the user to transact directly without relying on a third-party.

Around 2014, the industries focus shifted from Bitcoin to Blockchain, the underlying technology. At its core, Blockchain is an open, decentralized ledger that records transactions between two parties in a permanent way without needing third-party authentication. This creates an extremely efficient process and dramatically reduces the cost of transactions.

The features such as immutability, decentralization, privacy, traceability, reliability and trust is what makes Blockchain technology so exciting. This is one of the main reasons the world started to realize that Blockchain could be used for more than just the digital currency. Some of the use cases include supply chains, healthcare, insurance, transportation and voting.

According to [Sally Davies, FT Technology](http:// https://www.ft.com/video/2be94381-66dc-3320-a292-6a1cde0a3d5f) reporter “Blockchain is to Bitcoin, what the internet is to email. A big electronic system, on top of which you can build applications. Currency is just one”.

### How Does It Work?
Considering that Blockchain technology is disrupting industries from voting to banking, having a basic knowledge of it will be useful.

At it simplest form, Blockchain can be broken down into three components, namely transactions, blocks and links.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1zt6fkm6d75zyknalbjx.png)

Before we talk about the terms, let’s take a detour and talk about carriage trains. At this point you would be wondering, what has carriage train got to do with Blockchain? Well, it has nothing to do with Blockchain but it is a metaphor for explaining what transactions, blocks and links are to Blockchain technology.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/b0c3c7schm18polaw7jv.png)

At its core the passenger train has two components, namely locomotive (engine) and carriage/coach. All the components are connected via a coupler.

The carriage is normally of fixed size and has a limit of how many passengers it can accommodate. To get on the carriage, the passengers have to buy a ticket and the ticket will generally have information about what time the train departs, platform number and carriage number. If there are any seats available then riders will get a confirmation, and they can board the train else they have to go on a waiting list or wait for the next train.

This same principle applies to transactions and blocks. So if we go back to Blockchain, the **_transaction_** is like **the passenger**. However transactions can also be something else, just like different types of trains, such as freight train and passenger train. Transactions can also be a payment or a medical record. You can therefore define Blockchain transactions as a small unit of task that is stored in records. Generally there are two types of transactions, **_confirmed_** and **_unconfirmed_**. Confirmed transactions go into the blocks, where as unconfirmed transactions don’t. This is similar to getting a confirmed ticket to board the train else you have to be on a waiting list.

The block in Blockchain technology is similar to the carriage in the train. Basically, blocks are a record of confirmed transactions, and different types of Blockchain implementations will have a maximum size for a block, just like length of a carriage. For example, Bitcoin blocks have a maximum size of 1MB. Each new block will have a reference to the previous block in the Blockchain except for the first block. Like in the train we have engine, the first block in the Blockchain is called **Genesis block**.

If we go back to our example of train, a coupler is a mechanism used to connect carriages and the engine of the train, as shown in the image below. The coupler comes in different shapes and sizes. Buffer & chain, Link & pin and Bell-and-hook are few example of couplers.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qxzau62ksoqdewu11wmg.png)

Just like the coupler for trains, a similar concept is used in Blockchains to connect blocks. The blocks in Blockchains are linked to its immediate predecessor using a **_hash_**. The first block in the Blockchain is called the **_“Genesis”_** block or Block 0 and is almost always hardcoded into the software of the applications that utilize the Blockchain.

At this point you might be wondering, what is hashing and how it is useful in the Blockchain ecosystem. Worry not, I will try to explain it.

Hashing is simply a process of taking a variable length input and creating a fixed size output, which is sometimes also called a **_Digest_**. Just like different types of couplers for a train, there are also different types of hash functions. Example are Murmur hash, CityHash, SHA256, xxHash and SHA-3.

Blockchain mainly uses cryptographic hash functions such as SHA256 and Keccak-256. Example of Blockchains using these functions are Bitcoin and Ethereum, respectively.

The main reasons for using cryptographic hash functions for Blockchain lies in its properties, which are:

* **_Deterministic_** – each time you parse same input through the hash function, you will get same hash value. For example, if we pass Iron Maiden song “The Trooper” through SHA256 hash function 1000 times, then each time we will get the same hash value.
* **_Efficiency_** – for any given input, the hash function should be capable of returning the hash value quickly else the system is simply not efficient.
* **_Pre-image resistance_** – given a hash value, it should be difficult to find its input value. It is not impossible to determine the original input from its hash function.
* **_Collision resistance_** – two different inputs to a hash function cannot have same hash value.
* **_Variance_** – making a small change to the input will change the hash value completely. For example, just changing the first letter of the [Iron Maiden](https://en.wikipedia.org/wiki/Iron_Maiden) song **_“The Trooper”_** to **_“the Trooper”_** using SHA256 hash function changes the hash value completely.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8avhpkhnqzhd3h59mww8.png)

The following picture depicts a logical representation of the Blockchain. The block body is where the transactions reside.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yq7ur7kds4pqbu3p5jds.png)

Other variables in the Blockchain depends on the type of the Blockchain used by an application. For example, a Bitcoin block header not only contains the hash of the previous block header, but also version, merkle root, nonce, mining difficulty and timestamp.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bh3bho7cli3qq13uty0u.png)

Let’s say a malicious attacker changes a transaction data (tx1) in block 1 of the Blockchain above. Because of the properties of cryptographic hash functions,

1. A new hash value will be generated for hash(1) which in turn will generate a new value for hash(12) and so forth, so that in the end, the merkle root will have a different value.
2. Because of change in the merkle root value, the hash value of the block 1 header (hash(b1)) will change and that will change the hash value stored in block 2 and this will result in changes in block 3, and so on and so forth. Therefore, it will become difficult for the malicious attacker to compute an alternate chain from Block 1 which will catchup with and overtake the one true chain.

That's all there is to it. Hopefully, the connection between Train and Blockchain is now clear. I hope you can now easily explain Blockchain concepts to others as well.

If you are interested in learning more on Blockchain, you can get the copy of my ebook from [Amazon](https://www.amazon.com.au/Introduction-Blockchain-Whats-fuss-about-ebook/dp/B07MG8Z99R).

Next post will explore different types of Blockchain.

Also If you were wondering, **Iron Maiden**, is indeed one of my favorite bands.

------------------------------------------------------------------

Thanks for reading!

If you enjoyed this article feel free to share on social media 🙂

Say Hello on: [Linkedin](https://www.linkedin.com/in/harinderseera/) | [Twitter](https://twitter.com/harinderseera) | [Polywork](https://www.polywork.com/harinderseera) 

Blogging: [Dev](https://dev.to/harinderseera) | [Hashnode](https://harinderseera.hashnode.dev/)

Github: [hseera](https://github.com/hseera)