What is Hyperledger Fabric and how it works?

This is the first article in a series of articles whose final goal is to explain how to fully develop a blockchain web application using Hyperledger Fabric framework, Node SDK, Node.js and AngularJS. These articles are not written by blockchain professionals and they are the result of the multi-month learning process about blockchain technology from official documentation, fabric samples and other Hyperledger Fabric application examples that can be found on the internet. The application is developed within the start-up project initiated by the Comtrade Industry. Special thanks for guidance and infinite support to Milan Bundalo whose awesome ideas we have turned into reality.

Articles include these topics:

About the blockchain application that we are developing

Our application is called CryptoKajmak and it represents the example of the software solution that tries to eliminate problems for perishable goods (kajmak in our case) that exist in the trade industry by using new blockchain technology. The kajmak is the milk product with limited shelf life.

The kajmak

Umm delicious, right?

CryptoKajmak application has six business processes that represent main operations of the system. They are:

  • Adding a new user to an organization
  • Creating a new kajmak
  • Listing all existing kajmaks
  • Selling a kajmak
  • Mixing kajmaks
  • Automatic deletion of kajmak

Demo of the application can be found on this link.

But, before we start, we need to know the meaning of some terms that we will use and also we need to have the basic understanding how everything works in the blockchain network. Don’t worry, we tried to explain it in an easy way.

What is Hyperledger Fabric and how it works?

The term Hyperledger Fabric has multiple meanings. On the highest level, the Hyperledger Fabric is one of the Hyperledger projects hosted by The Linux Foundation. The Linux Foundation is the world’s largest open source software project.

The Hyperledger Fabric is also the name for the framework or platform that we use to build and deploy distributed ledger solutions for business. Main characteristics of Hyperledger Fabric are modular architecture, shared ledger, privacy that is achieved by using channels, confidentiality, flexibility and scalability. These characteristics make the Hyperledger Fabric suitable to use in different business systems because components are pluggable and they can be configured differently based on specific requirements.

On the picture below, we can see other Hyperledger frameworks and tools that exist.

Image taken from www.hyperledger.org

Key components and features of the Hyperledger Fabric framework are:

Blockchain network

Business organizations that have common interests and goals can collaborate with each other and on that way they form the network. The blockchain network is technical infrastructure that provides place to store data and transaction records called ledger. Besides the ledger, the blockchain network provides business rules and logic described in smart contracts, usually called chaincodes. Organizations in the network can form consortium which means that they follow the same set of network policies that are agreed by the consortium at the network configuration time.

Ledger

As we already said, that is the place to store some records. We can think about it as a journal of transactions. The blockchain ledger contains from two components. The first is the world state — a database where we store current values of a set of the ledger states in form of key-value pairs. By calling application’s functions we add new key-value pairs in the world state, delete them or we change existing value that corresponds to the specific key. The second component is the blockchain — a transaction log that records all the changes that determine the world state. Building units of blockchain are blocks of transactions. For example, if we call a function that deletes the kajmak, the kajmak will no longer be visible in the world state, but the delete transaction will be written to the blockchain so every move in the network is transparent to all participants that are part of the same channel. On that way, ledgers are immutable.

Channel

Channel is the communication link between the set of organizations in the network. Only peers from organizations that are part of the same channel can see ledger records for that channel. If, for example, two organizations want to share some private data, they can create new channel between them and all transactions on that channel will be visible only to them.

Peers

Peer nodes, or just peers, are the essential components of the blockchain network. Peers host one or multiple chaincodes and copies of the ledger.

There are three types of roles that peers can take:

Endorsing peers — they simulate chaincode functions against their copy of the ledger and return results back to the application. In other words, they provide an endorsement of the proposed ledger update to the application, but do not apply the proposed update to their copy of the ledger. We can configure the peer to be endorsing peer.

Committing peers — they commit transactions into the ledger. All peers in the network are committing by default.

The peer can be endorsing and committing at the same time.

Anchor peer — A peer node on a channel that all other peers can discover and communicate with. Each member (organization) on a channel has an anchor peer (or multiple anchor peers to prevent single point of failure), allowing for peers belonging to different organizations to discover all existing peers on a channel.

Orderer

Special node that sends transactions ordered into blocks to the committing peers. Orderer node is usually common for all organizations in the network.

Chaincode

This is the place where we define logic (functions) of our application. Chaincode needs to be installed on every peer that will interact with the ledger. It also needs to be instantiated on the channel. After that, end users can invoke chaincode functions through a client-side application that interfaces with a network peer.

Identity

There are different actors in the network: peers, orderers, client applications, administrators and more. Because the blockchain network is permissioned network, every actor needs to have digital identity in the network. Identity is represented in the form of the X.509 digital certificate. Actors can get certificate in the network creation time. Very often, we can’t predict how many participants our network will have, so we will have problem if we generate only certain number of digital certificates in the network creation time. To solve that problem, Hyperledger Fabric gives possibility to dynamically generate more certificates after the network is up and running.

We will learn in details about this process in one of the future articles. For now, you only need to know that you need digital certificate in order to be part of the blockchain network.

On the picture below we can see main structure of the blockchain network in the CryptoKajmak application and how previously explained components interact with each other.

Image represents the structure of the blockchain network in CryptoKajmak application. The network is made up of three organizations. Every organization have two peers. Two organizations (org1 and org2) make consortium and they are part of the same channel. Every peer from org1 and org2 will have copy of the channel ledger. Only peer0 from both organizations will call chaincode functions so we installed chaincode only on that peers. The third organization (org3) is admin organization and we will use it to dinamically add new users into the network with help of the Certificate Authority.

There is just one more thing we need to understand and we are ready to code.

Transaction Flow

Let’s pretend that you are the end user who wants to create new kajmak. In other words, you want to execute transaction for creating kajmak. What happens in the background?

Application sends our request to all endorsing peers. Endorsing peers simulate the function for creating kajmak from the chaincode against their copy of the ledger, sign responses and return them back to the application. Our kajmak is not committed to the ledger yet. Application then sends responses from the endorsing peers to the ordering service. Orderer node collects certain number of transactions, orders them and makes the block of transactions. The block is then sent to all committing peers who validate block and commit it into the ledger. This is the scenario if we want to write something into the ledger.

But if we only want to read something from the ledger, transaction flow usually ends when endorsing peers return responses to the application. In other words, application doesn’t need to communicate with the ordering service.

Now we are ready to bring up our first blockchain network. The beginning is always the hardest, but don’t give up. We hope to see you in the next chapter.

--

--