Load Balancing ESP32 IoT Data Streams Using HAProxy?

Hi all, I’m currently working on a smart sensor deployment where multiple ESP32 devices stream data over MQTT and HTTP to a central server. Inspired by this guide which shows how to build an ESP32-based IoT system with MQTT integration and real-time monitoring, I started thinking about how to scale the backend more effectively:
https://www.theengineeringprojects.com/2021/11/esp32-mqtt.html

To handle growing traffic, I’m considering HAProxy as a lightweight reverse proxy and load balancer between the MQTT broker (Mosquitto) and a REST API used for data visualization. I’ve reviewed similar approaches from the Eclipse IoT documentation and this HAProxy blog post on balancing WebSocket connections, but I’m not sure how well HAProxy handles frequent short-lived IoT connections, especially from constrained clients.

Has anyone used HAProxy in a similar IoT context? Any tips for optimizing connection reuse, TLS offloading, or using stick-tables for session persistence with many small devices?

There will be no connection reuse, when a MQTT client closes the connection to haproxy, haproxy closes the matching connection to the backend server.

For every connection on the frontend with a client there will be a corresponding connection to a backend server.

I don’t see any issue with TLS.

What I don’t know is how you’d like to handle the mosquitto part.

When a client connects to haproxy and is load balanced to mosquitto server 5, sends a few messages and disconnects, the association between the client and server 5 is gone.

When the same client connects next time, it can hit server 6. Does server 6 have all the messages for this client that server 5 received in a previous session?