How to assure data immutability in a sensor network?


In this article, we will explore the depth of the trust, privacy, and data immutability problem in the IoT network, and one of the innovative and creative prototyping approaches we used to solve it.

One of the important aspects when creating a sensor network or in IoT, in general, is how to create trust between different nodes of the network. Talking about trust requires talking about making the data private, secure, and immutable from any change. This where the Blockchain came into play.
The blockchain is a decentralized network of blocks, that contains records of data, and a hash of that data, which are linked in a cryptography way. Any change of any block data breaks the chain, which makes it immutable for changes. The use of a blockchain database, which can also be more secure and private than a centralized database, can solve our trust problem.

In a sensor network, we need to store a large amount of time series data in a small interval of time to process it, we need a powerful blockchain database that aligns with our values. We found different solutions such as IOTA, Xoaa, Streamr, Fluree, and BigchainDB.

After the research that has been conducted internally, we searched for different solutions that we can use for our solution. For different reasons, we decided to use a very promising solution which is BigchainDB to ensure security, privacy, and data immutability

The use of the BigchainDB in a sensor network

BigChainDB, in summary, is a blockchain decentralized database on top of MongoDB’s centralized database, which makes it a reliable, mature, and powerful solution. It has different characteristics as it is an asset-centric approach and not a data-centric approach, scalable, it uses the Byzantine fault tolerance using Tendermint, and it is Open Source.

When we talk about immutability, it is to make it impossible to change and modify the data inside a database. In a sensor network, We need to assure that the data are immutable from changes for a transparent, open, and trusted network.

How to verify immutability?

In our article, we need to verify the data immutability in the BigchainDB database. For that, we have used this approach:

  • Get data from an MPR (MQTT Payload Restreamer) which is used as a sensor simulator to send data. This module has been developed internally.
  • On top of Node-red, we have two other components:
    • An “MQTT In” module that gets data from our MPR.
    • An HTTP POST that store all the data in another PostgreSQL database
    • A NodeJS script that POST store data in the BigchainDB, it works in the following steps:
      1. Create the IoT owner keys, we have used the BIP39 method to generate a mnemonic phrase, that creates both the private and public key for the IoT owner, and we store it so we can have access to it.
      2. Create the IoT asset
        • Asset data is the device id of the sensor.
        • Metadata is the data that the sensors send.
      3. Using both CREATE transactions to create the IoT sensor and the TRANSFER transaction to update its value with the last data value.
  • For retrieving the data and verifying the immutability, we went to this approach detailed in the next diagram:

    1. In PostgreSQL, we save all the data that we got from the MPR sorted by the time it gets stored.
    2. In BigchainDB, we create the asset at first, and we only update the metadata each new data came from the MPR.


  • We created a NodeJS program that does the following:
    1. Get all the data from the PostgreSQL database.
    2. Get the list of the transactions in the BigchainDB that happens at that sensor ( You can search in the BigchainDB the list of transactions that happen for a certain element which is sorted by time). Using that list, we get the state of and the data in that transaction.
    3. For each transaction at the time t1, we compare it to the data in the PostgreSQL at the same time.

Final thought and conclusion

After finishing our program, we deploy it into our Digital Ocean Dedicated Server to do our test. After running the MPR for some time. We went to verify the data in our NodeJs program and compare each transaction with the data inside the PostgreSQL.

We concluded that the data is immutable inside the BigchainDB.

For privacy and security, it has the same level of security as MongoDB, and for privacy, you can’t alter data if you weren’t its owner ( you need to have the private key that enables you to do that) which make the BigchainDB a right solution for the privacy and data immutability with the sensor network.

Using the BigchainDB inside the IoT network will enable us to create an open, trusted, robust, secure, and highly available system.

Using blockchain technology in IoT does not only stops at its ability to create a trusted network only, but its uses cases can be extended in more innovative ways:

  • Using it for the Micropayment, as data becomes valuable for different parties ( companies, governments, and at the individual level), we can create a smart contract on top of our network that pays users automatically for their shared data.
  • Use different solutions in the smart contract on top of our blockchain solution to run the different programs automatically.
  • With a decentralized database such as BigchainDB, we can improve trust and create open networks between parties.
  • Increase the reliability of data, and reduce risks associated with “data downtime” (Only six years ago, data downtime cost companies a cumulative $1.7 trillion annually).

Like it?

Share it!