The most essential criteria that should be looked at when considering an enterprise IoT deployment is scalability. When there is huge traffic with very large amount of data, the scalability becomes a question? To overcome this, MQTT Broker cluster with robust and fault-tolerant high availability configuration is needed. But how does the devices in an IoT environment know which MQTT Broker to connect? Load balancing at the transport layer can address this challenge and ensure this with Azure load balancer will fit & scale your IoT applications. Bevywise MQTT Broker perfectly works with ALB and it is even flexible to be hosted in Azure VMs. This blog will take you to the tour of how to setup your highly scalable IoT implementation on Azure with Bevywise MQTT Broker.

A Little on HA MQTT Broker :

MQTT Broker with high availability is necessary to ensure that the MQTT communication occurs without any hindrances. By default, the publish and subscribe model MQTT Protocol doesn’t support high availability. But the high availability can be attained through simple steps with the right MQTT Broker. In that sense, our Bevywise MQTT Broker comes up with the high availability server which avoids such failures.

HA Architecture

Azure-load-balancer

Let’s take the above architecture as an example. This illustrates that a High availability server is installed in each machine that runs the MQTT Broker. A Load Balancer is configured to balance the loads between the brokers and the High Availability server in one is primary while those in others are just back-ups.

What function does a load balancer serve?

A load balancer’s goal is to increase productivity, shield your servers and resources from overload, and give users a quick, secure, and dependable experience. If you have two or more servers, you need to think about installing a load balancer. The key characteristics of a load balancer are listed below.

  1. Distributes traffic to healthy servers with adequate capacity, aiding you in preventing slowdown of your websites caused by an increase in traffic.
  2. Route traffic automatically to healthy, available servers to help you do server maintenance without experiencing interruption.
  3. Early server failure detection will be made possible, and traffic will be diverted to healthy, still-running servers.
  4. Provides you with comprehensive performance data, error alerts, and reporting to help your company plan, modify, and optimise its infrastructure.

Using the Azure Load Balancer to enable high availability :

Requirements for enabling high availability using Azure load balancer :

  • ‘N’ number of clients
  • MQTT Broker (more than 1)
  • A load balancer (Azure)
  • A HA Server
  • A Database

The number of MQTT Brokers can increase based on the count of clients. With the use of high availability server, link and cluster all the MQTT Brokers you possess. If either of the MQTT Broker fails, then the load balancer will decide which broker should take over the responsibility of the failed MQTT Broker and send messages to the connected clients, preventing the failure to happen. This is feasible as all the cluster nodes and brokers will receive all the MQTT messages.

Set up Azure as a load balancer in one of the machines. Azure load balancer health probe will keep track of each virtual machine’s assigned port and only routes traffic to operational virtual machines.

To configure Azure load balancer, take the actions listed below.

Step 1 : Upon logging in into the Azure portal, search for “Load Balancer” and select it from the results. Then click “Add.” In the “Basics tab,” precisely enter the following information, then click “Review + Create.”

  • Subscription : Select your subscription

  • Resource group : Select Create New and provide a resource group name in the text box

  • Name : Give a name

  • Region : Select the region of the server you use

  • Type : Among Internal and Public, select Public

  • SKU : Out of Basic and Standard, select Basic

  • Public IP Address : Select Create new. Choose Utilize existing if you already have a public IP address that you want to use.

  • Public IP Address name : Type the public IP address name in the text box

Once you finally click “Create,” your load balancer will appear.

Step 2 : Go to Networking > Virtual network under Create a resource. Enter the necessary project and instance information on the Basics page to build a virtual network.

A button labelled “Next: IP address” will then appear at the bottom of the page. Enter the IP address under the IP Addresses tab and choose the term ‘Default’ under the Subnet name.

To make changes, select Edit subnet and save anything you wish to change in the subnet category.

Step 3 : Choose All Resources > All Services. From the list of resources, choose your resource’s name. From the Settings menu, pick Backend pools > ‘Add’.

Enter the necessary information on the Add a backend pool page, then click Add. 

Step 4 : Select All Services > All Resources > Choose your resource name from the resource list to create a health probe. Select Health Probes under Settings, then click Add. Then click OK after entering the information on the Add health probe screen.

  • Name – Give a name to your health probe

  • Protocol – TCP

  • Port – 8883

  • Interval – 5 seconds

  • Used by – HTTP

Step 5 : By selecting All services > All resources >, you may create a load balancer rule. The resource list will appear; choose your resource’s name. Choose Load balancing rules from the Settings menu, then click Add.

Type in the required information and select Ok.

Finally click Create / Finish to create the load balancer.

Step 6 :¬†Locate and copy the public IP address from the load balancer’s Overview screen, then paste it into your browser’s address bar to test the load balancer. Verify the answer.

If you get a valid response, your load balancer has been configured properly and can communicate with the backend virtual machines.

Integrate Azure load balancer with MQTT Broker :

To integrate Azure load balancer with MQTT Broker, follow the below instructions.

  • Go to Bevywise/MQTTRoute/conf/broker.con

  • Provide the IP address of the load balancer that’s generated after setting it up

[HASERVER]

HASERVER_ENABLED = YES

HASERVER_IP = <IP address of Load Balancer>

HASERVER_PORT = 8082

Ensure that you’ve provided the load balancer’s IP in all the MQTT Brokers that are available in the clustered set up.

To configure HA Server :

For Linux users,

  • Unzip the HAserver.zip file which is present inside the ./Bevywise/MQTTRoute folder.
  • Then open ./HAServer/config.json file which is present inside the unzipped folder.
  • Configure the HA Server port. By default, HA Server runs at 8082.

To start the HA Server,

  • Open the terminal and go to ./HAServer/bin
  • Run HA Server using the command ‘sh startServer.sh’

Windows users can execute the exe file.

To know about database configuration, refer this blog.

Download MQTT Broker now for FREE to get started with your High Availability MQTT cluster.

Hope this blog has helped you understand how to configure the Azure load balancer to enable high availability. Try customising it yourself. The usage of Nginx load balancing by MQTT Broker to support high availability has already been thoroughly documented.

Please feel free to contact support with any questions or recommendations.