Eren Akbulut's Blog

MQTT Explained

January 18th, 2021

Hello everyone today I'll try to cover what is MQTT and why it's almost involved with all IOT applications.

Let's get started with the definition right away.

What is MQTT?

MQTT is a standard messaging protocol for IOT systems. MQTT is a super light weight protocol and that's one of the main features that makes MQTT one of the most important in the field. MQTT stands for Message Queue Telemetry Transport and actually developed in late 90s.

There are a few main terms in MQTT that everyone who is interested in MQTT needs to know about.

  • Broker

In a MQTT system all communication between all devices goes over a Broker devices. Brokers act like a middle man that can receive and transfer messages to all devices that can reach out to it. The transfer communication events described above is leading us to another point in a minute.

There are a few open source MQTT brokers out there and most of them are quite awesome but the most used one is the Mosquitto. MQTT brokers are usually so light weight they can work on literally any environment your pc, linux computer, mac or even most of the Linux based single board computers.

  • Publish and Subscribe

Publish and Subscribe is the words defining bidirectional data transfer background of MQTT, no clients stays in a direct contact with another client all the traffic works on Brokers with those roles. You a client can publish a message on a specific topic and all the subscribers of the topic will receive that message instantly. All sorts of devices from microcontrollers to normal personal computers can act as a client.

  • Topic

As we briefly used above, a topic is a way to categorize information in MQTT communication. Clients send or receive data by publishing to a topic or subscribing to a topic. There are others specifications about topics but this level of explaining is enough for the purposes of this guide.

  • QoS

QoS stands for quality of service in MQTT systems basically there are 3 modes we can select for our communication.

Mode 0 is a mode that publisher just sends and never checks for the answers.

Mode 1 is a mode that publisher sends over and over until it gets a confirmation.

Mode 2 however works like a total handshake, each data only gets published one this way and no message duplication happens like how might happened in Mode 1.

A basic MQTT example is visualized below:


Now let's talk about some other topics that makes MQTT so special.

  • I don't want to dive deeper into details but the thing you need to know is MQTT can scale up to millions "easily".( I mean that kind of a scale is never easy but relatively let's say.)

  • Different QoS levels allows you to define reliability/performance trade-offs for your system.

  • MQTT encrypts all the messages with TLS and ensures secure data transformation.

  • MQTT allows bidirectional data transfer and this is basically where all the magic happens.

  • I already mentioned about it a couple of time by, I don't think that was enough so let's repeat one more time. MQTT is Super LIGHT WEIGHT. It requires so little memory that you can use even the weakest Arduinos as clients or the lowest end single board computers like Raspi Zero as a Broker.

That's it everyone I tried to cover MQTT as clear as possible while giving as little details as I can to not to bore you. I hope you all enjoyed it. Until next time, take care :)

This blog has been created by Eren Akbulut 2020