esati
esati

Reputation: 35

Why separate database is needed in Hyperledger Fabric?

I'm newbie in Hyperledger Fabric and I do not seem to understand the use of LevelDB or couchDB in the this blockchain. Blockchain itself is supposed to be the database.

Thanks in advnance.

Upvotes: 1

Views: 1026

Answers (2)

Aurobindo Nayak
Aurobindo Nayak

Reputation: 44

Let me try to explain this. You see one of the fundamental attributes of a blockchain system was data immutability. Its basically designed to be an append only database. But in real life there are laws to deal with and developers needs a way to correct their mistakes. The workaround Fabric does is by introducing 2 databases.

The Leveldb is built on the peer nodes and has only CREATE & READ Access (You can't remove this from the Node). This makes it immutable fulfilling the property of blockchain.

The CouchDB on other hand is an add along database with full CRUD Access. You can update and delete data you want and this database is the one that handles the large scale data you would store and display on the front end application. Remember that this database is optional to use.

When you create a hyperledger application the data is stored as shown below. There are 2 databases created for every peer (assuming you have a couchdb attached)

enter image description here

Upvotes: -1

Navitas28
Navitas28

Reputation: 777

Hyperledger Fabric as a blockchain is a permissioned network that allows confidential transactions between known entities on the network without the use of cryptocurrency. To interact with Fabric network we use programs commonly referred to as chaincode in fabric or more commonly as smart contracts in other blockchain networks.

To address your first question, the use of LevelDB or CouchDB in the blockchain is to store transactions that are performed by the use of chaincode on the state of contracts present in the network. As LevelDB provides an optimized way of storing key-value pairs as compared to other DB's it is used.

To elaborate further Ledger consists of two types of records :

  1. TxN Logs - They are stored in level DB and are immutable as they are immutable, a simple DB with less overhead was a clear choice hence level DB.

  2. State - By default this is also implemented in LevelDB but since in real-time application you will need to execute queries on the DB to get some insights out of data there is an option to replace it with CouchDb which provides a sql-like query language to perform actions.

To answer your second question, blockchain is supposed to be a database that is just one side of the coin. The blockchain contains many other parts like permission networks, certificate authorities, the database is just one part of complete blockchain specifically if we are talking about Fabric.

Upvotes: 2

Related Questions