High availability MQTT Cluster is very important for any IoT deployments in production environment. Failures can happen due to Software failures, Disk errors, network connectivity, Hardware component failures, etc., To ensure that your services are up and running always to your customers without a single point of failure, the services need to be functionally and physically redundant. By default MQTT protocol a publish and subscribe model does not support high availability. But the resilient and fault tolerant MQTT high availability set up can be done with simple steps with the right MQTT Broker. With the latest release, Bevywise MQTT Broker comes up with the high availability server which avoids failure for MQTT communication. This article helps you to set up a high availability MQTT Cluster with the high availability server of Bevywise MQTT Broker.
Database Cluster High Availability
Data Storage is a crucial component of any production application. It is mandatory to have a Master/ Slave set up for your database storage. You can refer to the Digital Ocean document below for setting up the same.
Alternatively, you can use Amazon RDS or Azure Data Store (https://azure.microsoft.com/en-in/services/mysql/) which by default provides the redundancy of the data storage and much more features like time-based snapshots for recovery.
Dockerize the MQTT Broker
You can either run the MQTT broker using our scripts or dockerize it if needed. A Complete article on how to dockerize the MQTT Broker is available here. Dockerizing will provide you some assistance in service manageability like auto restart and more. You can get your copy of the FREE MQTT Broker from the download page.
The distributed cluster set up
High availability server is designed to ensure that the broker is consistently functional without any failures by creating a cluster set up. The cluster set up benefit yourself by enabling failover if any of the MQTT Broker you are using is inaccessible. Consider if you have numerous devices connected to the single MQTT Broker / server. There is a high chance of any malfunctions to happen, and the MQTT Broker may eventually fail, losing the data. This is where a clustered set up comes in. This distributed architecture enables you to have two or more MQTT Broker / servers, that if one of the Broker / cluster node stops working, the other cluster node/MQTT Broker will perform taking the responsibility without any interruptions on the client side. The cluster nodes are considered to be the MQTT Brokers.
For ambitious MQTT deployments with many millions of clients, any number of broker nodes can be deployed & the data can be distributed maintaining stability and availability. Even if network splits occur or any kind of connectivity problem between nodes arises, the cluster as a whole is still available, as long as at least a single node is still healthy, and heals itself in error scenarios. This is because, whatever be the count of MQTT servers, everything will be in active state, and the data will be distributed between the nodes. So, the healthy one will take the role of publishing the data to the subscribed client.
A Role of Load Balancer
The high availability cluster set up also includes the Load balancer. The role of this load balancer is to balance the incoming connections to your broker infrastructure. It is a decision maker to decide which MQTT Broker/server/cluster node in the cluster should take the role of failed MQTT server. The decision could be based on the weightage or the performing ability of the MQTT Broker. Install any load balancer of your choice and set up port forwarding.
How to set up High Availability MQTT Broker
Let us consider you have 6 clients & two MQTT Brokers 1 & 2 finally one load balancer & a high availability server.
Here is how the set up could be.
The two MQTT Brokers are connected & clustered using the high availability server. The MQTT messages will be distributed between all the brokers & cluster nodes. So if any of the broker fails, the load balancer will decide which MQTT Broker should start publishing the messages to the connected clients. This prevents failure.
To enable the high availability set up, do the below mentioned configurations in the conf file.
Here you can configure the HAServer port number and connect the broker with HAServer.
HA_port = 2000
Now Open terminal & go to ./Bevywise/MQTTRoute/Bevywise/HAServer/bin
& run sh startserver.sh for linux
Double click startserver.bat for windows
The configuration should also be done in the broker.conf file with this HAServer IP and port
DISTRIBUTION_ENABLED = NO
# YES || NO
# The port and the IP Address to which the HA server is running
# If you run the HA server in another machine. Use the IP of that machine.
DISTRIBUTION_IP = 127.0.0.1
DISTRIBUTION_PORT = 2000
Set the distribution enabled as YES.
DISTRIBUTION_IP & DISTRIBUTION_PORT refers to the IP address & port to which the HA server is running.
If the HA server is running in another machine, mention the IP of that machine.Your MQTT high availability cluster set up is ready now. Hope this blog post provides a clear understanding on high availability cluster. Try yourself by setting it up.
Bevywise MQTT Broker is the fastest & best MQTT Broker that will be helpful if you are planning to run an IoT deployment of tens of thousands of devices for a single business or a few business that falls under a single use case.
Download MQTT Broker now for FREE to get started with your High availability MQTT Cluster. The new version MQTTRoute 3.3 is released now with Mobile App to manage & monitor your MQTT devices right from your android smart phone. Get the app now on Google Play store.
Feel free to write to support for any queries or suggestions.
For large scale deployments, try Bevywise IoT Platform by signing up for free which is hosted at mqttserver.com All our products can be white labelled and used on any private cloud infrastructure or in premise.