DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Last call! Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • How to Scale Out Milvus — Vector Similarity Search Engine
  • Zero Trust for AWS NLBs: Why It Matters and How to Do It
  • XAI for Fraud Detection Models
  • Deduplication of Videos Using Fingerprints, CLIP Embeddings

Trending

  • AI's Dilemma: When to Retrain and When to Unlearn?
  • Comprehensive Guide to Property-Based Testing in Go: Principles and Implementation
  • Breaking Bottlenecks: Applying the Theory of Constraints to Software Development
  • Stateless vs Stateful Stream Processing With Kafka Streams and Apache Flink
  1. DZone
  2. Data Engineering
  3. AI/ML
  4. Load Balancing — MQTT Broker Clustering Part 1

Load Balancing — MQTT Broker Clustering Part 1

A quick introduction to MQTT message broking, the challenges of clustering, and then load balancing.

By 
Zaiming (stone) Shi user avatar
Zaiming (stone) Shi
·
Jan. 21, 22 · Analysis
Likes (3)
Comment
Save
Tweet
Share
20.5K Views

Join the DZone community and get the full member experience.

Join For Free

This post gives a quick introduction to MQTT message broking, the challenges of clustering, and then load balancing.

MQTT the Protocol

Maybe you are not that familiar with MQTT protocol, you probably know HTTP protocol very well. Like HTTP, MQTT works at the same network (transport) layer TCP/TLS (well, it can actually work on top of HTTP, but that’s a topic for another day).

According to https://mqtt.org:

MQTT is an OASIS standard messaging protocol for the Internet of Things (IoT). It is designed as an extremely lightweight publish/subscribe messaging transport that is ideal for connecting remote devices with a small code footprint and minimal network bandwidth. MQTT today is used in a wide variety of industries, such as automotive, manufacturing, telecommunications, oil and gas, etc.

MQTT clients are also similar to HTTP clients: they establish TCP connections to a server and send and receive data. The difference is that HTTP uses a request/response model, while MQTT uses a publish/subscribe model.

A real-life example: a temperature sensor in the living room periodically publishes its readings to an MQTT broker. A smart-home application subscribes to the temperature readings and makes smart-home decisions for you. For example: turn on the air conditioner when it’s above 32-celsius degrees.

The Scalability Challenges

A temperature sensor at home is only an example close enough to everybody. To serve smart home devices, a single MQTT broker, e.g. EMQ X edge edition running on a Raspberry PI should be more than enough, not to mention that a single EMQ X node can handle up to 2 million connections.

Now imagine these examples: millions of cars all over the world; millions of street lights all over the country; and so on and so on, the number of devices (MQTT clients) and data volume may be large enough to overwhelm any single MQTT broker can handle.

This is one of the reasons why we need to create a cluster of MQTT brokers. But it also creates more challenges such as:

  • MQTT broker discovery: how should clients know which broker endpoint to connect;
  • MQTT subscriber session takeover in case a client disconnect from one node and reconnect to another;
  • The global routing table has to be consistently shared across all nodes in the cluster

The first two challenges can be well addressed by putting a load balancer in front of the cluster.

MQTT Load Balancing


MQTT Load Balancing

To meet the above challenges, a load balancer should be able to help clients to decide which broker to connect based on configured balancing strategies. The primary functions of a load balancer for MQTT broker cluster are:

  • Broker endpoint discovery. The clients only need to care about the address of the load balancer, but not the individual brokers. This also creates flexibility for brokers to relocate, scale up or down.
  • TLS termination. Many MQTT broker users choose to terminate TLS in the LB, so the resources in brokers can be well dedicated for message processing.
  • Evenly distribute the load among the brokers. Load balancers are typically configurable for balancing strategies, such as random, round-robin (which has various weighted versions), and most interestingly: sticky dispatch.

Since MQTT is a protocol on top of TCP/IP, load balancing can be done at the transport layer. As a matter of fact, unlike many different choices we have when it comes to HTTP, most of the load-balancing products today (Aug. 2021) are still working at the transport layer. For instance, AWS NLB, Nginx, and HAProxy.

In addition, to transport layer load-balancing, HAProxy 2.4 and NGINX plus and also provide application-level MQTT load-balancing.

NGINX Plus is an application delivery platform built on NGINX, an open-source web server, and reverses proxy for high-traffic sites. This article from Nginx Plus gives a nice introduction to its MQTT load balancing solution.

Equally excellent as NGINX, HAProxy is free, open-source software that provides a high availability load balancer and proxy server for TCP and HTTP-based applications, (and now MQTT too). As of August 2021, HAProxy is the only free load-balancer that has MQTT protocol awareness. There is a brief introduction to the feature in their release note.

In the next article, I will use HAProxy 2.4 + EMQ X 4.3 to demonstrate full provisioning in detail.

MQTT Load balancing (computing) clustering

Published at DZone with permission of Zaiming (stone) Shi. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • How to Scale Out Milvus — Vector Similarity Search Engine
  • Zero Trust for AWS NLBs: Why It Matters and How to Do It
  • XAI for Fraud Detection Models
  • Deduplication of Videos Using Fingerprints, CLIP Embeddings

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!