Implementing Block Chain in Audit Log Management using MongoDB

sourabh sahu
5 min readOct 30, 2021

Audit Log Management is one of the key areas for use of block chain technology.

What is BlockChain?

Blockchain is a concept of storing information in such a mechanism that makes it legitimate and impossible to change, manipulate, hack, or cheat the system.

A blockchain is a ledger of transactions that works in digital space using compters, all the transactions and ledger is duplicated and distributed across the network of computer systems that are available on the blockchain.

Each block in the blockchain stores a number of transactions and every time a new transaction occurs on the blockchain, a record of that transaction is added to all ledgers in the distributed environment. The use of distributed ledger Technology is reffered to managing ledgers with multiple participants.

Blockchain is a type of DLT in which transactions are recorded with an immutable cryptographic functions called a hash functions. The hash functions generates the same value of same data. Slightest of changes in data will always leads to new hash values. The hash functions is used to validate and verify the data or transactions.

The change in any block of a blockchain , it would be easily be tracked that it is tampered, If hackers wanted to corrupt the whole blockchain system, it require to change in whole chain and each node, that would be extremely difficult and can easily be tracked.

Crypto currency like Bitcoin, DogeCoin, Ethereum, etc. uses blockchain technology

How Blockchain can be implemented using MongoDB?

Blockchain concept can be implemented using MongoDB. Blockchain application be layered as

  1. application layer
  2. blockchain layer
  3. database layer

The application layer can UI based transactions like Stock Application, Inventory application. The block chain layers deals with decentralized distributed property of the block chain. It also provides immutability that records changes will be reflected to each block of chain and asset transfer that is to be recorded to ledger. Database layer uses rich queries, scalability and distribution is required in block chain application. It should be enterprise hardened.

Add alt text

The Decentralized process to implement blockchain technology can be used using MongoDB. MongoDB Querying is suitable for blockchain. Scaling of monodb includes high capacity, high throughput and low latency that will help in easy implementation of blockchain. The shading of mongodb supports scaling requirement of blockchain. Operationalization of Mongodb is aligned with blockchain requirements.

Add alt text

The Mongodb supports multiple administrators that is requirement of multiple ledger managers using blockchain layers. The Following architecture of blockchain can be implemented using Mongodb.

Decentralization. Each database co-administrator controls one of the nodes in the database. Each node is a MongoDB node. All nodes of MongoDb forms the blockchain networks.

Immutability: MongoDB provided backup functionality for each node transaction is hashed and pushed to other block to provide immutability.

Assets. The ability to create and transfer assets is part of the API, where the client creates a transaction in MongoDB

Blockchain Application : Audit Log Management

The blockchain concept can be implemented in various domains like Finance, Banking, Identity Management, Audit trail, Healthcare, Medicines, etc. One such area that can be benefitted using block chain is Audit Log Management.

Audit Log Management: Audit Log Management is process of recording the operations performed in accessing data, modifying the data and visualizing the data. The Audit Log Management consist of data collection, storage, protection, parsing of the data and its subsequent analysis.

An audit log has become vital part of any application dealing with data. Audit log provides the view to check what had happened over the period of time. This information can be asked by any government & legal agency to validate the operations of the respective application for any dispute or breach or possible tampering of data. So it’s clearly understandable that Audit Log has to be tamper- proof. This can be used a perfect example for application of blockchain.

How to Create Block Chain and Store Log Data in MongoDB?

Blockchains are used as a digital ledger to store transactional information. The data is stored as signed blocks that is hash function values using cryptographic functions, which link to each other using previous value of hash, creating a chain of immutable interconnected data block.

Add alt text

Create Database: use audit_block_chain;

Create collection using following command

db.createCollection(“audit_chain”);

Add alt text

Hash function: cryptographic function that provides the immutable hash code derived from the data and stored the block. In mongodb, hex_md5 can be used for generating the hash values.

Db.audit_chain.find().forEach(

function(doc){

hash.Value = hex_md5(doc.data);

db. chain.save(doc);

}

);

Genesis Block: It is the start of chain, that is first block of chain with no data.

Genesis Block

Applying hash function

Hashing key component

Viewing the record

Add alt text

Transaction Block: Transaction block is the subsequent blocks of the chain.

Add alt text

The following queries is being executed on terminal with mongodb to view the block of the block chain.

  1. Show collections()
  2. Db.collection_name.find()

The execution and output of the queries is shown below.

Add alt text

Add alt text

You can reach out to me in case of any issue/suggestions

--

--