Simple IoT Messages Delivery With GoLang — 1

Rafael Costa
4 min readFeb 5, 2022

I believe that in 2021 anybody knows what IoT is or at last heard this term, but most people don't know how IoT Based Systems work in the real world and how many technology/tools there are around these systems. In this series of articles, I try to give you some idea of how we can create a real-world IoT system using some commercial tools to help us. But first, let’s take a look at some IoT concepts.

We can describe a simple IoT System using this picture below:

Picture 1: Simple IoT System

As we can see in the picture we have two actors: The “things” and the cloud applications. The things are devices with having the capability to convert physical phenomena to electrical signals (transducers), same times process these signals and send those signals to “internet”. When we need to send messages over the “internet” we need to use some protocol to do this right? The most used protocol to transfer data over the “internet” is HTTP or HTTPS.

These devices most of the time have processing and memory limited, and the HTTP/HTTPS and so many other “internet” protocols have a somewhat heavy implementation, in addition, the HTTPS doesn't have bidirectional communication. Most of the time HTTP/HTTPS is not the best choice to work in the IoT context, because when we think about IoT we need some protocol more efficiently, here MQTT going in. MQTT (MQ Telemetry Transport), is a lightweight bidirectional messaging protocol for sensors and small mobile devices optimized for TCP / IP networks, if you want to improve on the subject you can find more information here.

At this moment we can see that the block called CLOUD APPLICATIONS in picture 1, may contain some applications, and now we know that the “things” send data over MQTT protocol from our cloud systems, the MQTT protocol use the broker mechanism to deliver the data, so when we seed our data to the MQTT Broker to do something with this data the broker is responsible to distribute the data to any application which need it.

When we start to deliver our data to other programs and this program have heavy processing, this can cause serious problems in the MQTT Broker because when some program connects to our broker with a subscriber and our program spends a lot of time to finish their job, our program starts to consume a lot of broker resources. Because of that same times when our IoT system has a lot of devices and we need to do a lot of things when our data come into MQTT Broker, we need a strategy to reduce the broker’s cost.

To improve the broker resources we can initially remove all data from the broker and send it to a queue system, once the data are into the queue system we can handle the data the way we need without worrying about the time it will take. The picture below shows us the concepts.

Picture 2: Distributed IoT System

The pice of our system is responsible to get MQTT data and putting this data into a queue is called MQTT Bridge, in this case, we created an application that handles the In and Out data flow, but we can create two separated applications to handle this job, one for in and other for out. Before our data into the queue, we can do anything we need in any system.

Now we know the concept about what will we build, in the next article we going to talk about the stack we going to use and start to configure our environment to build our application.

Conclusion

We saw the principle concepts around the IoT systems and how the conventional IoT system has serious problems with scalability. Before we talk about a simple way to improve our IoT system and can scale our IoT system easily.

You can read the next article: Simple IoT Messages Delivery With GoLang — 2

--

--

Rafael Costa

Backend Engineer— [GoLang] [Rust] [IoT] [IIoT] [NodeJs]