While most blockchain platforms are developed to achieve broad goals and provide many options for implementation, some solutions choose to target more specific areas, like IOTA does for the Internet of Things (IoT).
In our previous article, we looked at how IOTA can be used with some particular IoT devices, learned about the consensus algorithm, and explored one of IOTA’s use cases — to power an application for automated toll road payments. However, we focused on client devices that use IOTA.
In this article, we describe how to combine IOTA and IoT to create a large-scale system. As an example, we take a smart city network and explore how to make this system safely and reliably store data from hundreds of IoT devices.
This article will be useful for blockchain developers who are interested in ways to implement the IOTA platform and for anyone who’s intrigued by the idea of developing an IoT smart city solution based on the IOTA platform.
IOTA is a unique next-generation shared public ledger that promises speed and scalability — features desired by most blockchain networks. At its core, IOTA uses an innovative technology called the Tangle instead of the traditional linear blockchain data structure.
Based on a directed acyclic graph (DAG), the Tangle is a completely new approach to creating a blockchain ledger. This innovative data structure allows processes in IOTA to take place quite differently — and more efficiently — than in other blockchains.
IOTA doesn’t use the traditional design that’s applied to most blockchain networks. Instead of chaining blocks one after another, each block references the two previous blocks. So the structure no longer looks like a chain. Instead, it resembles a mesh or a tree — or a “Tangle.”
In a Tangle, consensus is achieved by checking if a transaction is reachable in the DAG from every open tip. Tips are newly created blocks that are still unapproved in the Tangle. Each incoming transaction needs to choose two tips to approve. There’s always at least one tip in the network.
If a transaction is reachable from all tips, it’s considered confirmed. For example, if there are 100 open tips and a transaction is reachable only from 80 of them, then the transaction is considered to be 80% confirmed.
The consensus algorithm used in IOTA allows nodes to add their transactions to the Tangle autonomously. There’s no risk of foul play, as other nodes won’t verify invalid operations. This unique approach to creating and validating blocks is the source of most of IOTA’s advantages. No wonder lots of developers use IOTA to launch Internet of Things projects.
The unique approach to the public shared ledger proposed by IOTA eliminates some crucial issues of traditional blockchains, as IOTA’s Tangle has no blocks, no miners, and no chains.
Now let’s take a closer look at the three major benefits of the IOTA platform.
Currently, most popular blockchain networks have extremely low transaction speeds. Some networks are capable of less than 100 transactions per second (TPS), which is not enough for any serious application.
Thanks to IOTA’s Tangle, the transaction speed increases proportionally to the number of platform users. This eliminates any possible transaction bottlenecks.
The biggest benefit of the Tangle is its exceptional scalability. Traditional blockchain networks are built with blocks of information, each block being connected to the previous via a cryptographically calculated hash. IOTA solves the scalability issue by making every transaction approve at least two other transactions instead of storing transactions in blocks with a limited size.
As more transactions are added to the DAG, more tips become available for confirmation, which in return increases the capacity for new transactions. This allows the network to scale easily.
Often, running a full blockchain node requires a dedicated server with lots of computational power. Bitcoin is regarded as one of the largest power hogs among blockchain networks. A single Bitcoin mining node requires a lot of expensive mining equipment and several megawatts of electricity per year.
IOTA reduces costs by eliminating key areas of the conventional mining process such as searching for hashes.
The Proof of Work algorithm in IOTA doesn’t require constant searching for block hashes. Instead, a node simply verifies two previous blocks in the DAG, which makes nodes lighter. Moreover, in this way, IOTA eliminates transaction fees, as each node “pays” for its transactions by performing this proof.
The benefits mentioned above claim to solve the major issues of conventional blockchain networks and allow IOTA to be used in projects for various industries. To see if this claim is true, let’s try to combine IOTA and the Internet of Things to build a large-scale application for a smart city system.
The Internet of Things extends internet connectivity to physical devices and everyday objects. One of the ultimate use cases for IoT applications and devices is a smart city.
A smart city incorporates information and communication technologies to enhance the quality and performance of urban services such as transportation and utilities in order to reduce resource consumption, waste, and costs. The goal of a smart city is to enhance the quality of life for residents through smart technology.
Everything from traffic lights to buildings is connected to the smart city network. This network includes thousands if not millions of devices, each producing and consuming a lot of data. Thus, creating such a network requires a scalable, fast, and secure system.
This network should be able to handle thousands of operations per second, ensuring stable operation of all kinds of devices such as sensors, smart appliances, cameras, and cars. Connecting so many devices to a conventional blockchain like Bitcoin or Ethereum would be impractical, as transactions on these networks are too slow and expensive.
With IOTA, the more devices you connect to the network and the more transactions are performed, the faster and more stable the network becomes. So using IOTA for smart cities development is an obvious choice for such a system.
A smart city produces lots of data, and it must be efficiently and reliably stored. Sensor data can be used for automatic utility payments, data can be analyzed to optimize the behavior of various components, and so on.
However, since IOTA doesn’t have a linear blockchain structure, retrieving data isn’t simple. You have to parse all of the previous nodes in order to find the necessary information, which requires lots of time. Additionally, data doesn’t become available right away. Instead, it spreads as nodes in the network receive new blocks from the DAG.
All of the data that’s added to the IOTA network is eventually added to the DAG. In this way, storing data is similar to passing mail on a train. You place a message at one stop by putting it into the DAG, and the recipient retrieves it later.
The biggest downside is that by storing large amounts of data in the network, the DAG becomes too large to handle efficiently. IOTA solves this issue by creating snapshots.
Snapshots are performed periodically to clear out the network and keep it as fast as possible. In IOTA, a snapshot isn’t a data backup but a process wherein all transaction history gets reset. Snapshots only save information about coin balances. A node can be configured to keep a set number of blocks available; the rest get pruned to save space. Unfortunately, all data stored in the pruned blocks is lost.
To keep track of all of the data in the network, IOTA came up with permanodes that never perform snapshots, so all transactions remain stored. These nodes are expensive to run, as they require a lot of storage. So permanodes usually provide paid access to an API.
For a use case such as a smart city, having dedicated permanodes will be more convenient than accessing third-party nodes. A dedicated node will reduce latency and, probably, reduce costs in the long term as more requests are made to retrieve the data.
We’re going to use IOTA to build a decentralized network for devices in a hypothetical smart city. Before connecting all IoT devices in our smart city into a single IOTA-based network, we need to make sure that this network is scalable. To check that, we have to consider what bottlenecks may occur.
There are two major issues we should keep in mind when planning the network architecture:
- Network latency affects the time it takes for a single transaction to be distributed through the network.
- Node performance affects the number of transactions that can be processed by a single node.
There’s not much we can do about network latency. Using the fastest networking technologies — like fiber cables and 5G mobile networks — is desirable but not always possible.
Fortunately, block propagation is not a significant issue. Since IOTA nodes can add blocks to the Tangle autonomously, there’s no need for ordinary nodes to be fully synchronized with the network at all times. Nodes can add transactions to the Tangle simultaneously, and transactions will be shared among the network over time.
The network achieves scalability by letting nodes run independently. The main bottleneck for network scalability is transaction propagation latency. The network simply can’t transfer data between nodes as fast as the data is generated.
With IOTA, not all nodes have to know about every single transaction in the network. Since the DAG is not linear, new transactions can be added anywhere. Over time, some transactions will be shared among nodes. Nodes will be able to confirm others’ transactions, and consensus can be achieved.
On average, a single node should be able to handle about 100 TPS. Each node should be connected to several neighbors to be able to share transactions among them for confirmation. If a node is connected to four neighbors, each neighbor can create around 20 TPS.
By chaining arbitrary amounts of neighbors like this, it’s possible to achieve any transaction capacity over a distributed network. For example, with 5,000 nodes, the network should be able to handle around 100,000 transactions per second (distributed evenly across all nodes).
Let’s start building our network by looking at its possible architecture.
The IOTA network we propose for a smart city consists of three layers:
- Outer layer
- Middle layer
- Inner layer
The outer layer consists of all small client devices. These can be IoT components such as smart sensors, appliances, cars, traffic lights, bus stops, and even buildings. Additionally, the outer layer contains data processing components such as AI data centers that monitor the city. All of these outer layer components are simply clients connected to the network.
The middle layer consists of nodes that can perform and validate transactions. This layer is the main workforce of the network. Data transmitted by IoT devices can be handled by nodes in this layer and sent as transactions to the network.
Finally, the inner layer contains permanodes for data storage that simply collect and store all data created by each device in the network. These nodes provide the full history of smart city life.
In a previous article, we described the process of setting up and running a client for a smart car that automatically pays road tolls. Now, we’ll focus on setting up a network for such devices.
We’ll use the IOTA reference implementation (IRI), which is written in Java. So technically, it can run on any platform. Linux is usually preferred, since it’s easier to set up.
You can run a node on a dedicated server or a virtual private server hosted in the cloud (e.g. AWS or Digital Ocean). In our case, running dedicated servers all over the city would be the best choice, since it will lower the access latency. However, running a few permanodes in the cloud for backup is also a good idea.
There’s a great community guide that provides detailed step-by-step instructions on how to launch a node. The five basic steps to setting up a single IOTA node are:
- Configure the environment
- Install the node
- Configure the node
- Add security and monitoring
- Launch the node
A reverse proxy is necessary to protect nodes from denial of service attacks and to allow requests to nodes to be encrypted with HTTPS. This helps to secure both a node itself and the data passed to and from the node. So this component is mandatory for our smart city, as a network on the scale of a whole city can be subjected to all kinds of attacks.
On the other hand, monitoring may not be as crucial. Monitoring tools allow node operators to keep track of the state of their nodes. For example, you can see the number of incoming and outgoing requests, measure resource load (CPU, RAM, disk usage), and detect any malfunctions (e.g. if the node is down). While these metrics are useful, we don’t need to monitor them closely for every single node on the network. To reduce hardware requirements for the server, we can omit monitoring for middle-layer nodes.
Another important thing to note about node configuration is the permanode parameters. By default, snapshotting is enabled in all IOTA nodes. This means that approximately every 28 days, a local snapshot will be triggered and all data older than 28 days will be deleted. To disable pruning, we have to set a configuration flag in the iota.ini configuration file:
LOCAL_SNAPSHOTS_PRUNING_ENABLED = false
This way, snapshots will never be pruned, so the node will keep all transactions in its history — making it a permanode.
Once we’ve set up each individual node, we can connect the nodes to each other to create a network. By default, the IOTA reference interpretation doesn’t connect to any neighbors (peers). To connect several nodes together, we can either define a set of neighbors in a configuration file using the NEIGHBORS option or use the node’s
addNeighbors API function.
In fact, we can also connect our nodes to the main IOTA network. With other networks, private projects such as smart city ecosystems require a private blockchain network, as public networks are oversaturated with other transactions and there isn’t much capacity left. If a network were based on Ethereum, for example, there would be no way to use the mainnet. Even if we don’t take transaction fees into account, using the Ethereum mainnet would slow the network to a halt.
Fortunately, this isn’t a problem with IOTA. As we mentioned, the network can easily scale to accommodate as many clients as needed. In fact, connecting such a large project to IOTA would be beneficial for the platform, as the more nodes are using it, the more stable the network becomes. There’s a potential issue of data privacy when connecting your project to the main network, but it can be solved by properly encrypting data before sending it to IOTA.
To connect our nodes to the main network, we simply add some neighbors to some of our nodes from the mainnet. The nodes will slowly sync and send our transactions to other nodes in the mainnet.
Since our nodes are mostly connected with each other, they’ll probably favor their own blocks to attach new transactions to the Tangle. Thus, we’ll create a subtangle.
There’s nothing special about this subtangle. Unlike in a linear blockchain, which may have sidechains and forks, the DAG has no real structure. So a subtangle is simply a group of transactions in the Tangle. Moreover, since tip selection is probabilistic, some other transactions will likely be mixed in with those coming from our part of the network.
There’s only one disadvantage to connecting our nodes to the main network: Permanodes will have to store both data useful to our smart city and unrelated data on the network. Unfortunately, there’s no simple way to filter out stored data. We could create a separate backup worker that would read data from the DAG and store it in a separate database. However, this solution greatly centralizes the network, creating the danger of a single point of failure.
IoT Toys: A New Vector for Cyber Attacks
When it comes to IoT applications, lots of small actions and events are happening on thousands of client devices. Therefore, there’s no doubt that using a blockchain network can help bring order to the chaos.
Unfortunately, most conventional networks like Bitcoin, Ethereum, Ripple, and EOS lack the capacity to support such a large number of transactions. IOTA, on the other hand, uses innovative technology to create a network that’s scalable, fast, and secure.
With IOTA, it’s possible to configure the network in a way that allows thousands of clients to connect simultaneously. By dividing responsibility between layers of nodes, we can create a network that’s able to efficiently handle any kind of load for smart cities based on IOTA.
A significant advantage of the proposed architecture is the connection to the main IOTA network. This connection won’t affect performance in any way (unlike in other networks), as block propagation latency isn’t a problem in IOTA due to the mainnet connection. Although synchronization can occur gradually, connecting a lot of active clients to IOTA will be beneficial for the whole network, as the speed and security of the network scales with the number of users. Therefore, using IOTA for smart city projects is a promising direction.
At Apriorit, we have an experienced team of blockchain developers who keep an eye on new blockchain solutions and their integration into IoT systems. Get in touch with us to start your ambitious project!