AWS Quantum Ledger Database (QLDB) With Node.js and Ionic
What is QLDB?
Let me steal the definition from Amazon website as that’s the best definition I found — “Amazon QLDB is a fully managed ledger database that provides a transparent, immutable, and cryptographically verifiable transaction log owned by a central trusted authority”.
This means QLDB is centralized ledger database where data is always inserted, never updated, keeping history of all the changes made to the database. Well, you can achieve similar functionality just by using your favorite relational Database such as MySQL or Oracle. But what you can’t guarantee is the immutability. With administrative privilege of database, someone can delete the audit log which is not possible with QLDB ( at least at the time of writing this article). Moreover each transaction is cryptographically verifiable more like blockchain transactions.
QLDB vs Blockchain
The basic and most important difference between QLDB and Blockchain is — QLDB is centralized ledger whereas Blockchain is distributed ledger. There are certain use cases where your organization wants to keep track of an asset such as vehicle ownership or a deal life cycle but other organization does not need to participate in the transaction or act on the data. This type of use-cases don’t need the complexity of Blockchain and QLDB is a perfect fit.
Tutorial & Demo
In this article I am going to demonstrate one application written in Ionic. Backend is written in Node.js which interacts with QLDB using qldb driver. Backend architecture is serverless. Code is deployed as Lambda and REST layer is created using API Gateway. Entire source code checked into Github.
I have created one QLDB Ledger named DealLedger and one table named Deal. Loaded 3 records into Deal table. I saved all the query and data in samepledata.txt
Backend API is written ExpressJS and deployed to Lambda so that one API Gateway can serve multiple REST endpoints.
Okay, enough of AWS Serverless, let me show you the meat :) Below is the IONIC app where I am going to change the status of deal id 108570 to Scanned.
Let’s look at the data from Deal table below. QLDB maintains a current state of the data same as World State in Hyperledger Fabric.
Let’s click on the “History” button which retrieves all the changes made to the deal 108570. We should see 2 entries, one with status “saved” and other with status “scanned” as expected. Also notice Doc ID remains same for the deal id but Tnx ID and Block ID change whenever any modification made to the data.
The most important and attractive feature of QLDB is cryptographic verification which is basically re-calculating hashes ( SHA-256) to ensure integrity of data modification. Using cryptography, you can easily verify that there have been no unintended modifications to your application’s data.
Thanks for reading and keep learning !