What is MQTT?

Man driving a car
March 02, 2023
Written by
Reviewed by

What is MQTT - Banner

The Internet of Things (IoT) and Machine-to-Machine (M2M) communication have a lasting impact on the way we interact with technology. The number of connected IoT devices is expected to have grown 18% to 14.4 billion globally by the end of 2022, with approximately 27 billion connected IoT devices estimated by 2025. With this growth, a messaging protocol that can handle real-time, reliable, and efficient communication between devices and processing systems (typically sitting in the cloud) is essential.

This is where the MQTT protocol comes into play. MQTT has become the de facto standard for IoT and M2M communication due to its lightweight and scalable nature. In this blog post, we'll explore the ins and outs of MQTT, how it works, its advantages, and use cases.

What is MQTT and what is its history?

MQTT is a messaging protocol designed for efficient communication between remote devices with limited network bandwidth and small code footprint. It uses a publish-subscribe messaging transport model and is widely used in industries such as automotive, manufacturing, telecommunications, oil and gas, and many more. MQTT is a standards-based protocol that enables machine-to-machine communication and is commonly used in the IoT ecosystem to transmit data between low power, resource-constrained IoT devices and the cloud. Specifically, MQTT uses a small code footprint and is well-suited for devices that have limited processing capabilities and/or available memory.

MQTT is an open OASIS standard and an ISO recommendation, making it widely adopted and well-supported by various software and hardware vendors.

Originally, the "MQ" in "MQTT" was derived from IBM's MQ (then known as MQSeries) product line, where it stood for "Message Queue". However, despite its name, the protocol does not utilize message queues; instead, it provides publish-and-subscribe messaging: devices publish messages on a specific topic, and all devices that are subscribed to that topic receive the message. Its main applications include sending messages to control outputs, and read and publish data from sensor nodes.

The specification, which was opened by IBM as version 3.1, referred to the protocol as "MQ Telemetry Transport." Subsequent versions released by OASIS refer to the protocol simply as "MQTT," while the technical committee overseeing the protocol is called the "OASIS Message Queuing Telemetry Transport Technical Committee." Since 2013, "MQTT" no longer stands for anything, but instead is simply the name of the protocol.

What are the components of an MQTT architecture?

MQTT implements the publish/subscribe model through its two main components: clients and brokers.

Clients are devices or applications that publish or subscribe to messages, making them so-called Publishers or Subscribers, respectively. A client can publish a message to a topic, which is a logical channel to which the message is sent. Subscribers, which can be one or more clients, receive messages that are published to a topic. Clients can also act as both a publisher and a subscriber.

Brokers, on the other hand, are intermediary servers that route messages between clients. Brokers manage the distribution of messages between clients by keeping track of subscriptions and publishing messages to subscribed clients. MQTT clients can be implemented in a variety of programming languages and can run on various hardware platforms, ranging from low-power microcontrollers to powerful servers. Brokers can be deployed in the cloud or on-premises and can be scaled horizontally to support millions of devices and messages per second. Hyperscalers such as AWS or Azure also offer MQTT wrappers around their services, with varying levels of support for the MQTT protocol.

MQTT Diagram

When a subscribing client loses its connection to the broker, the broker can – depending on the use case and implementation – retain any messages that are intended for the subscriber and then deliver them as soon as the subscriber reconnects. This ensures that the subscriber does not miss any messages and receives them in the correct order.

How is MQTT used in IoT?

The following are a few examples of how MQTT can be used in IoT and Industrial IoT (IIoT) infrastructure, highlighting its flexibility and versatility for a variety of applications:

  • Smart metering: MQTT can be used to ensure accurate meter readings are transmitted in real-time with reliable message delivery, leading to more precise billing.
  • Ambient sensor data: MQTT is well-suited for gathering low-priority data from sensors used in remote environments, making it an ideal choice for IoT sensor buildouts.
  • Machine health data: MQTT can ensure the reliable delivery of machine health data to local teams, even before the information hits a data center, making it an excellent choice for monitoring the health of critical assets such as wind turbines.
  • Billing systems: By adding additional ways to ensure resilience, MQTT can help reduce duplicate or lost message packets in billing or invoicing systems, making it suitable to support the accuracy of these critical operations.

MQTT broker implementations exist from the likes of HiveMQ, Thingstream, Mosquitto, AWS IoT, and Azure IoT.

For a technical deeper dive into MQTT, consult the specification, which you can find for the latest version of MQTT 5.0 here. Note that different implementations, such as the ones mentioned above, support and interpret the specification differently.

How does Twilio support MQTT?

Twilio IoT offers two device builder platforms that target different audiences: Twilio Microvisor, and Twilio Electric Imp. The product team gave an overview of both platforms back in 2020 in a webinar “Build Connected Devices on Twilio IoT’s New Platforms

Twilio Microvisor helps experienced firmware engineers and hardware builders to get their devices connected to the Internet through a light-weight, unopinionated cloud and device-side offering. Developers can continue to use the programming language and operating system of their choice (or none at all), e.g. C or C++ on Azure RTOS, while benefiting from capabilities such as secure firmware over-the-air updates, secure remote live debugging, and secure boot. Twilio Microvisor is currently in Beta and supports MQTT with sample implementations (GitHub) available leveraging Amazon FreeRTOS with support for standards-compliant brokers. Interested engineers can sign up for the Beta Program and apply for receiving a free dev board.

Twilio Electric Imp also helps companies build Internet-connected devices, but targets businesses without noteworthy hardware or firmware expertise. It offers an easy-to-learn high-level scripting language that abstracts the complexities of the underlying hardware, and also offers secure firmware updates and device management capabilities. Electric Imp is GA and offers an MQTT API and sample code.


Note: ChatGPT was used to help with phrasing and parts of the content production. Our engineers reviewed all content for technical accuracy before publication.