Blockchain Explained: A Shopping Cart Analogy

Esmund
6 min readAug 3, 2018

--

Note that there’s a distinct difference between cryptocurrency & blockchain; with the former being just one implementation of latter. We will only be focusing on blockchain in this article.

A cartchain analogy

Enter the next tech buzz-word: blockchain. Touted as the “revolutionary leap forward, bringing power to the people, new age of internet” amongst other claims, it has travelled from the shadows of dark web into the financial center of Wall Street. In a nutshell, it’s just a special kind of data storage.

“a growing list of records, called blocks, which are linked using cryptography” as wikipedia puts it.

To understand blockchain, you must first understand a concept known as a hash function. It is with this function that blockchain is built upon. To put it simply, a hash function basically turns any data into a fixed length value.

To fully explain about hash and its role in blockchain, let’s go shopping

Imagine there exists a high-tech shopping cart that can analyse any items in it into an unique and unpredictable barcode. You know, the barcode that is on every product’s packaging.

Some important attributes about the barcode :

  • The barcode represents everything as a whole, that was in that shopping cart. Nothing more, nothing less.
  • Any exact combination of items will always result in that exact barcode.
  • Anyone can check what items are represented by any barcode but impossible to predict what items will produce what barcode.

To illustrate this, suppose a tomato in the shopping cart will yield the barcode ID:010.

ID:010

Add a grain of rice, and the resulting ID might be 123454321; totally unpredictable but unique to its specific contents. The barcode will be generated even if the above scenario is repeated a million times.

ID: 123454321

With this, we know that ID:010 will always represent a tomato, however there is no way to figure what ID:00005555222 represents.

What could this be? Nobody knows

Some of you might be thinking, couldn’t someone work that out by testing all combinations of different items and thus becoming predictable?

You would be right but wait! We will deal with this in a bit.

We have now covered the important bits of hashing, let’s move on its role in blockchain. We know by design, carts (or blocks if you must) are “linked” together in a chain. But what does it exactly mean?

Beautifully drawn illustration of the 2 carts

Let’s continue with the previous example. We call the cart with tomato “cart 1” and let’s take another cart, and call it “cart 2”. Suppose there are some potato chips in it. To “link” the two cart together, write “cart 1”’s ID:010 on a piece of paper and put it in “cart 2". The idea is to always include the previous cart’s ID in the next cart to link them in order.

We now get a barcode of ID:52 for “cart 2” (as we mentioned, ID will be random but unique to a specific set of contents).

If we were to place just the potato chip only, or substitute ID:010 with different ID, we will get a very different barcode.

This is where the crux of the word “chain” of “blockchain” comes from, by including the previous cart’s ID, we cryptographically link them together & derive the exact order of all the carts.

I can’t proclaim that the third cart is actually the second in line — anyone can refute that claim by pointing out that the third cart’s paper slip contains second cart’s ID.

Cart 2 is linked to cart 3. No way around it

This will also prevent the scenario where someone could record every possible item combination to “game” the lucky draw; as the previous ID introduces an unknown variable in to the mix and changing the new resulting ID unpredictably.

That being said, it wouldn't make much sense if everyone started having their own shopping cart chain and couldn't agree on a single source of truth. Imagine if everyone couldn’t agree on what red looks like; red wouldn’t be red anymore.

We need a consensus mechanism. Not just any consensus, one that is trustless — one even strangers can agree on

How do we achieve this? Let’s move to the ingenuity of “proof of work”.

They are all strangers, I swear

To add a little excitement to the whole shopping experience, we decided to hold a lucky draw and shopper who win gets the items in their shopping cart for free. Naturally, there are a horde of shoppers trying to win at the same time.

The lucky draw is conducted as such: The first shopper who gets a barcode id ending with 1234 and submit their receipt to the service counter will win. Whenever someone wins, the winning shopping cart’s ID will be announced and another round with a different barcode id requirement will commence.

Now, for the interesting twist. To qualify for the prize, the previous winning cart’s id must be in the winner’s cart. Because of this requirement, nobody can work out the barcode ID ahead of time.

That is to say, even if I know previously that apple pie & orange juice produce a barcode id ending with 12345, it wouldn’t be of any help — if I were to add in the paper slip of the previous winning cart, the barcode id of apple pie & orange juice & paper slip (with previous winning cart ID) will result in another unknown arbitrary number.

Food items shown are for illustration purposes and does not reflect the real product

Additionally, there is no chance of foul play as everyone will have access to the winning cart items and be able to verify that the paper slip with previous winning cart is included in the new winning cart & the winning barcode ends with the required number.

The collective effort in “guessing” the next cart is to ensure a certain amount of “work” goes into each new winning cart. This makes it incredibly difficult & costly for any single party to “win” carts consecutively.

Don’t be this guy

To further understand why, picture an evil shopper who wants to manipulate the winning cart to contain only baby products as a joke. He or she would basically need to outbid every shopper by consecutively being the first to find an ID that fits the ID criteria. One could, in theory, spend tons of resources to obtain sufficient processing power to do this but in practice, the cost of doing so significantly outweigh the benefits.

This makes it so that blockchain’s data cannot be tampered, altered or otherwise edited. Any data in the chain will always be immutable by design.

If the shopping cart contains cheques instead of food item, you’ll quickly notice why this is so important. Each cheque can be traced back to the order it was issued, if it was even issued at all, and that issued cheques cannot be tampered with.

Of course, there are several other concepts involved in blockchain, but we won’t go into that in this article. So there you have it! A very general look using shopping cart as an example. Stay tuned for more !

--

--

Esmund

Android Software Engineer. Dabbles in everything at a whim.