IBM Db2 / © 2018 IBM Corporation
Simplifying Analytical Reporting for Blockchain Applications — Vinayak Agrawal Developer Advocate for Analytics [email protected] @dapper_hack_er
Who are we?
2
Developer Advocates for Analytics We build code patterns for various analytics use-cases based on customer requests.
What were we trying to do?
• Build a sample insurance application for an insurance company.
Our Blockchain application has 4 peers:
1.Shop – A storefront that sells expensive sporting goods. Also sells insurance on them.
2.Insurance Organization – Partners with shop and offers insurance
3.Police – Cerifies claims filed by customers.
4.Repair Shop – Administers repair requests.
3
Problem: Blockchain becomes a transaction repository. So how to find insights about the business running on it?
4
1. How many Insurance Policy were sold?
2. How were they sold over a period of time?
3. What were the products mostly bought with insurance?
1. How much revenue did the insurance company make?
2. Which insurance policy bought the maximum revenue?
1. How many insurance claims were filed?
2. For which product the maximum claims were filed?
3. How much $$ was paid out in claims?
1. How many claims were filed which couldn’t be verified by the policy?
2. Which customer filed fraud claims?
Options we Tried with Hyperledger Fabric Blockchain (1)
5
1. Fabric SDK
Our Observations:
1. Learn Go
2. Learning Curve
3. Limited Functions
4. No Analytical functions
Lets Code!!
6
Options we Tried with Hyperledger Fabric Blockchain (2)
2. Peer chaincode Cli
This is what it looks like
Our Concerns with Custom Approach
7
Skill gap
Learning Curve
Custom Code Maintainability
Security
Access Control
For our Customer, we needed Ease to Use, Rich Analytical Functions, Stability/Scalability and Security
8
Easy to Use – Python, SQL
Bridging the Skill Gap
Analytical Intelligence
Rich Analytical Functions
We needed Ease to Use, Rich Analytical Functions, Stability/Scalability and Security
9
Stability and Scalability
Performance and Concurrency
Security like a data management solution for access control
We found solution to all those problems with IBM Db2. So we developed something new in Db2.
1
0
Solution Simplified View
1
1
1. A Db2 federation wrapper that provides:
– Connectivity to Blockchain Transactions via Hyperledger Rest API
– Rewriting SQL queries into equivalent Hyperledger API calls to query data.
2. Using Zeppelin (can use any JDBC supported tool) as end user tool to connect to Db2.
3. Query Blockchain via Zeppelin using SQL.
Honors the security measures in place at Blockchain level and Db2 level for end users.
End User
User Interface
JDBC connection
Federation
Hyperledger Fabric
1 2
3
4
How does the solution work?
• The Fabric ledger is maintained by each peer and includes the blockchain and world-state
• A separate ledger is maintained for each channel the peer joins
• Transaction read/write sets are written to the blockchain
• Channel configurations are also written to the blockchain
• The worldstate can be either LevelDB (default) or CouchDB
• LevelDB is a simple key/value store • CouchDB is a document store that allows
complex queries • The smart contact Contract decides what is
written to the worldstate
Overview of Hyperledger Fabric Data Model (Txs & World-State)
How does the solution work?
Difference between Transaction and World State
1
3
# Transaction Initiator Receiver Amount
1 Create a/c Cash Matt £1000
2 Create a/c Cash Dave £2000
3 Transfer Matt Dave £100
4 Create a/c Cash Ant £500
5 Transfer Ant Matt £50
6 Transfer Ant Dave £200
7 Transfer Dave Matt £100
8 Transfer Dave Ant £50
9 Transfer Matt Ant £50
Transactions
• What’s Dave’s balance?
• Does Matt have funds to clear a £1000 transaction? (Assuming no overdraft)
Matt.balance = £1000
Dave.balance = £2150
Ant.balance = £350
World State • It is clearly not feasible to reparse the entire transaction
log to complete a new transaction • Blockchains often include an associated database (world
state) – e.g. Hyperledger Fabric • Transactions become a set of creates, reads, updates
and deletes of records in this data store
Our Focus from Analytics Perspective
How does the solution work?
Architecture
1
4
IBM Db2 Big SQL
How does the solution work?
Fabric
SDK
Wrapper
Runtime Flow
1
5
How does the solution work?
Fabric
SDK
Wrapper
End use Experience (Peer chaincode vs Db2)
1
6
Our Vision
• Easy and Secured: (Addressing the Skill Gap)
-In place querying, reporting & analytics of Blockchain data using the rich SQL language support provided without compromising the Blockchain security model.
• Data Virtualization: (Fits into Analytics Infrastructure)
-Joining Blockchain data with other enterprise data set (Hadoop, Hive, Spark, external RDBMs) for complex use cases without additional work
-Immediate support for all Db2 based products through Federation
17
Blockchain Traditional Database
Reporting Tools
Connect to Blockchain just like any other database
Data Access Layer
Data Repositories
What is the current status and how you can try it?
Currently this enhancement is coming out in IBM Db2 11.5 (June 27th ).
You can try it out by downloading/cloud IBM Db2 11.5 Free Version at (clickable):
Db2 Docker Image
Db2 on IBM Cloud
Db2 on AWS
Db2 Desktop Edition
1
8
Resources
[Video] Blockchain Analytics with Db2 - https://youtu.be/3tPBdIr0lA4
For Demo, Details and latest updates,
Follow Db2 on Twitter: @IBM_Db2luw
Follow me on Twitter: @dapper_hack_er
1
9
Thank you
20 IBM Db2 Augmented Data Explorer/ © 2018 IBM Corporation
Vinayak Agrawal
Developer Advocate
—
+1-412-660-7784
21 IBM Db2 / © 2018 IBM Corporation
Demo – Screenshots available in Appendix
22
Demo – Insurance Business Network
We will be using a insurance application for this demo which has 4 participants (peers) in the business network. 1.Shop - A business front that sells cell phones, bicycles and ski. They also sell the insurance for the respective products.
2.Insurance Organization - The organization that is the insurance provider of policies and is also responsible for managing and processing claims.
3.Police - Police works in the network to provide validity on a insurance claim regarding theft of the asset.
4.Repair Shop - If a claim is filed to be repaired then repair shop gets request from insurance agency and completes the repair. The customer only interacts with the shop to buy an asset and insurance organization to file claims if needed.
Demo – Insurance Business Network
24
Create the Blockchain Wrapper in Db2
25
Creating Username Mapping, Nickname and Querying
26
27
Sample Questions for Insurance Peer
28
Insurance Peer Exploring Data
29
Insurance Peer identifying interesting columns
30
Performing Analytical Queries
31
Performing Analytical Query (II)
32
Performing Analytical Query (III)
33
Performing COMPLEX Analytical Query (IV)
34
Performing Complex Analytical Query (V)
35 IBM Db2 / © 2018 IBM Corporation