Layman’s Terms — IoT’s beloved PUB/SUB Model (MQTT/XMPP/Many More)

Himanshu Kotnala
IEEE Student Branch DIT University
3 min readMay 31, 2020

In today’s ever-evolving technology-centric world, keeping one’s self-updated is not an easy task! And being a developer makes it worse as there are many fields to explore. Today’s Agile methodology based development requires a basic understanding of the work of other teams too, which requires an understanding of the stack they use. Hence this series will focus on describing technology using the common day to day products we use.

With this modern era full of smart devices launching every other day, a question always arises on how to do these so-called smart devices work and make our work easy. While some devices can work independently like smartwatches, most of them aren’t smart enough with their key component Internet. Which raises the next question: how are these machines able to communicate without any human intervention? Well, that’s because of a special set of protocols known as M2M( Machine to Machine ) Protocol specially designed for the same task, most popular of them are MQTT, CoAP, XMPP, and many others.

Data transmission in IoT is governed by the aforementioned protocols. As IoT requires an asynchronous data flow, most of the protocols used in IoT are based on the Publish/Subscribe model.

Whenever we hear ‘subscribe’ the first thing that hits our mind is ‘Like, Share and Subscribe! Don’t forget to press the bell icon’, a common phrase used by all YouTubers. So we’ll try to understand the Pub/Sub model from the viewport of a content creator and a viewer on youtube.

As we all know a user can be both a content creator and a viewer. So if we want to get notification from a specific channel of youtube we first connect with youtube and login via credentials and then go to the channel, press the subscribe button, and the bell icon. Now, as soon as the content creator uploads a new video we get a notification on your phone/browser.

Similarly, IoT’s of Pub/Sub Models work. Every pub/sub model has two components: a client and a broker. So we can say a client is the youtube user and the broker is the youtube itself. Like a youtube user, a client can be both a publisher and subscriber i.e. publisher can be considered as a content creator while a subscriber can be considered as a viewer. Also, we have a concept of Topic which can be considered somewhat equivalent to channel except any user can publish to any topic (till the configuration has not been changed). Also like youtube a user, a client can also unsubscribe from a topic, set Quality of Service (like a bell icon), and many more features.

Summary:

In a Pub/Sub model, the first client initiates a connection with the broker, and once connected they can publish data to the broker and also subscribe to the required topics they may need data for further processing. Now it’s the responsibility of the broker to make sure that once a client publishes data on a specific topic broker should send the data to all the clients who have subscribed to that topic. All this communication is asynchronous and most libraries handle the message using callback functions.

Fun Fact

One of the most commonly used unrecognized IoT based devices is the one almost everyone must have used at least the one who earns ;p i.e. the ATM, in use since 1966 which communicates with a user bank server( database ) over the Internet.

Guys, if you like the article don’t forget to give a clap! Also, suggest the next topic for this series in the comments. Happy Learning :D !!!

Beginners Guide to MQTT: https://www.hivemq.com/mqtt-essentials/

--

--