MQTT Broker: How It Works, Popular Options, and Quickstart

EMQ Technologies
8 min readJun 21, 2023

Table of Contents

What Is an MQTT Broker?

MQTT is a lightweight protocol that supports the Internet of Things (IoT). This article explains the functionality of its central hub known as the MQTT broker, compares its various implementations, and reviews its use cases, features, and best practices.

An MQTT broker is an intermediary entity that enables MQTT clients to communicate. Specifically, an MQTT broker receives messages published by clients, filters the messages by topic, and distributes them to subscribers.

Using MQTT brokers to enable the publish/subscribe (pub/sub) communication model helps make MQTT a highly efficient and scalable protocol.

Why Are MQTT Brokers Important?

The MQTT broker plays a crucial role in the MQTT architecture, as it is responsible for facilitating communication between MQTT clients (publishers and subscribers).

Here are some of the main reasons MQTT brokers are important:

  • Message routing: The MQTT broker receives messages from publishers and routes them to the appropriate subscribers based on their topic subscriptions. This ensures that messages are delivered efficiently and accurately, without the need for clients to establish direct connections with each other.
  • Scalability: MQTT brokers can handle a large number of simultaneous connections, which is essential for IoT and M2M communication scenarios, where there may be thousands or even millions of connected devices. The broker’s ability to manage these connections and messages enables the MQTT protocol to scale effectively.
  • Security: MQTT brokers can provide security measures like authentication and encryption to ensure that the data transmitted between IoT devices and applications is secure. Learn more: 7 Essential Things to Know about MQTT Security 2023.
  • Integration: MQTT brokers can integrate with other communication protocols and cloud platforms to provide a complete IoT solution. For example, MQTT brokers can integrate with AWS IoT, Google Cloud IoT, or Microsoft Azure IoT Hub to provide a seamless IoT ecosystem.
  • Session management: The MQTT broker is responsible for managing client sessions, including maintaining information about the client’s subscriptions and handling messages that are retained for delivery to clients when they come online. This session management feature ensures that messages are not lost when clients disconnect and later reconnect to the broker. Learn more: MQTT Persistent Session and Clean Session Explained.

MQTT Broker Architecture

The MQTT broker architecture is based on the publish-subscribe messaging pattern, which decouples message producers (publishers) from message consumers (subscribers). This architecture includes three primary components: clients, topics, and the broker.

  • MQTT Broker Server

The MQTT broker is a server that receives messages from publishers and delivers them to subscribers based on their topic subscriptions. It manages client connections, handles subscriptions and unsubscriptions, and ensures message delivery according to the specified Quality of Service (QoS) levels.

  • MQTT Clients

MQTT clients can be publishers, subscribers, or both. Publishers send messages to the MQTT broker, while subscribers receive messages from the broker. Clients can be any device or application that can establish a connection to the MQTT broker using the MQTT protocol, such as IoT devices, mobile applications, or other servers.

  • Topics

Topics are hierarchical strings that define the subject or category of a message. When publishers send messages to the broker, they associate them with a specific topic. Subscribers express their interest in receiving messages by subscribing to one or more MQTT topics. The broker then routes messages to the appropriate subscribers based on their topic subscriptions.

The MQTT broker architecture can be either centralized or distributed. In a centralized architecture, a single broker handles all communication between clients. In a distributed architecture, multiple brokers work together to provide a scalable and fault-tolerant messaging infrastructure. Each broker in a distributed architecture can coordinate with other brokers to manage message routing, ensuring messages are delivered to the intended recipients.

Overall, the MQTT broker architecture provides a flexible and efficient messaging infrastructure that enables devices and applications to communicate securely, efficiently, and at scale.

Popular Open Source MQTT Brokers

EMQX

EMQX is currently the most scalable MQTT broker for IoT applications. It processes millions of MQTT messages in a second with sub-millisecond latency and allows messaging among more than 100 million clients within a single cluster. EMQX is compliant with MQTT 5.0 and 3.x. It’s ideal for distributed IoT networks and can run on the cloud, Microsoft Azure, Amazon Web Services, and Google Cloud. The broker can implement MQTT over TLS/SSL and supports several authentication mechanisms like PSK, JWT, and X.509. Unlike Mosquitto, EMQX supports clustering via CLI, HTTP API, and a Dashboard.

Mosquitto

Eclipse Mosquitto is an open-source MQTT broker for MQTT protocol versions 5.0, 3.1.1, and 3.1. Mosquitto is lightweight and can be installed on low-power, single-board computers or enterprise servers. The broker is written in C programming language and can be implemented on MQTT clients with a C library. It can be downloaded for Windows, Mac, Linux, and Raspberry Pi. Ready-to-install binary files are available for all operating systems. The latest version includes an authentication and authorization plugin “mosquitto-go-auth,” a web user interface for managing Mosquitto instances. It also offers a PHP wrapper “Mosquitto-PHP” for creating MQTT clients in PHP.

NanoMQ

NanoMQ is a lightweight and fast MQTT broker designed for the IoT edge. NanoMQ is implemented in purely C, based on NNG’s asynchronous I/O with a multi-threading Actor Model, and fully supports MQTT 3.1.1 and MQTT 5.0 protocol versions. NanoMQ is high-performance in the context of a stand-alone broker. The fascinating advantage is its portability. It can be deployed on any POSIX-compatible platform and runs on different CPU architectures such as x86_64, ARM, MIPS, and RISC-V.

VerneMQ

The VerneMQ project was launched in 2014 and initially developed by Erlio GmbH. As the second broker wrote in Erlang/OTP, the project is licensed under Apache Version 2.0 and borrowed some code from the EMQX project. Regarding architectural design, VerneMQ supports MQTT message persistence in LevelDB and uses a clustering architecture based on the Plumtree library, which implements the Epidemic Broadcast Trees algorithm.

How to Choose an MQTT Broker? Resources to Help Your Evaluation Process

The following articles will help you evaluate and select the best MQTT broker for your organization’s needs.

Evaluation Criteria

Looking for the perfect MQTT broker in 2023? Consider these 7 essential factors before making your choice. Read our guide for more.

MQTT Broker Comparison

In this post, we’ll explore the top open-source MQTT brokers in 2023 and compare them in-depth to help you choose the best one for your needs.

This article compares the top 3 MQTT brokers for IIoT in 2023, including each broker’s advantages, disadvantages, and use cases.

Discover the differences between EMQX and Mosquitto as popular open-source MQTT brokers in 2023 — read our in-depth comparison!

Compare EMQX and NanoMQ MQTT brokers in 2023 to choose the best fit for your IoT project. Explore their scalability, security, and reliability in our guide.

Read our comprehensive analysis of EMQX and VerneMQ MQTT brokers to make an informed choice for your IoT project.

This blog post will compare Mosquitto and NanoMQ as MQTT brokers and help readers determine which is better suited for different use cases in 2023.

This article sorts out some popular free online MQTT brokers, which we hope will provide a reference for your choice.

MQTT Broker Benchmark Testing

Discover the Open MQTT Benchmark Suite for the unbiased evaluation of MQTT brokers’ scalability and performance.

Find your ideal MQTT broker for IoT in 2023 with our open comparison analysis. Get comprehensive benchmarking insights now.

Compare the performance of Mosquitto and NanoMQ with Open MQTT Benchmarking in this comprehensive analysis. Discover the right MQTT broker for your needs.

Comprehensive benchmarking results of EMQX and NanoMQ on performance with Open MQTT Benchmark Suite, helping you choose a suitable MQTT broker.

Compare the performance of EMQX and Mosquitto with Open MQTT Benchmarking in this comprehensive analysis. Discover the right MQTT broker for your needs.

Compare the performance of EMQX and VerneMQ with Open MQTT Benchmarking in this comprehensive analysis. Discover the right MQTT broker for your needs.

To stress-test the scalability of the MQTT broker EMQX, we established 100M MQTT connections to the clusters of 23 EMQX nodes to see how EMQX performs.

Useful Resources to Help You Get Started with MQTT Brokers

Getting Started

This page will help you start with the fully managed MQTT service — EMQX Cloud- by providing a step-by-step guide on creating an account and exploring its features and characteristics.

This article will take EMQX as an example to introduce how to build a single-node MQTT broker on Ubuntu.

EMQX MQTT broker supports multiple security authentications, this article will introduce how to enable SSL/TLS for MQTT in EMQX.

MQTT Broker Integration

In this article, we will introduce how to integrate the monitoring data of EMQX 5.0 into Prometheus, use Grafana to display the monitoring data of EMQX, and finally build a simple MQTT broker monitoring system.

IoT data collection involves mass equipment and data, EMQX + ClickHouse is fully capable of IoT data access, storage, analysis, and processing.

We will use ThingsBoard Cloud in conjunction with EMQX Cloud to describe how to integrate a third-party MQTT broker into ThingsBoard to access MQTT data.

This article introduced the operation process for accessing the MQTT broker by using Node-RED and processing the MQTT data before sending it to the broker.

EMQX: World’s Most Scalable MQTT Broker

EMQX is one of the most popular MQTT brokers and has 11.5k stars on GitHub. The EMQX project was launched in 2012 and is licensed under Apache version 2.0. EMQX is written in Erlang/OTP, a programming language for building massively scalable soft real-time systems.

EMQX is the world’s most scalable MQTT broker that supports advanced features such as MQTT 5.0, MQTT-SN, and MQTT over QUIC. It supports masterless clustering for high availability and horizontal scalability. EMQX 5.0, the latest version, scales to establish 100 million concurrent MQTT connections with a single cluster of 23 nodes.

EMQX offers rich enterprise features, data integration, cloud hosting services, and commercial support from EMQ Technologies Inc. Over the years, EMQX has gained popularity among enterprises, startups, and individuals due to its performance, reliability, and scalability. EMQX is widely used for business-critical applications in various industries, such as IoT, industrial IoT, connected cars, manufacturing, and telecommunications.

Product page: https://www.emqx.com/en/products/emqx

Originally published at www.emqx.com

--

--

EMQ Technologies

EMQ is an open-source IoT data infrastructure software provider, delivering the world’s leading open-source MQTT message broker and stream processing database.