Mosquitto Clustered Architecture for High Availability(HA) and Load Balancing(LB)
• Bridge Cluster – Set of active bridge nodes, broadcast incoming/published messages to remote nodes.
• Remote Cluster – Set of active remote nodes, Each remote node sends incoming messages to all subscribers of that particular node.
• HA Proxy Cluster – Set of HA proxy nodes in master-slave mode. Master is an active node handles all the requests in roundrobin fashion. Incase master goes down passive slave node gets elected as master.
• Keepalived – Linux library runs as a daemon in both active and passive haproxy nodes. It performs failover on transport layer.
• Virtual IP – Private network floating IP gets rotated in HA proxy cluster.
• Public IP – Public IP is mapped to Virtual Private IP.
• Device/Gateway – Publish data to cluster over MQTT.
• Cloud Application – Subscribe to cluster for device data over MQTT
For above setup we need total 6 machines. One machine for each haproxy master and haproxy slave, 2 machines for mosquito bridge nodes to handle mqtt publish traffic and 2 machines for mosquitto remote nodes to handle mqtt subscribe traffic (note - specific to my usecase).Here, all publish messages from device and applications are handled on port 1883 and subscribe messages on port 1884.