Horizontal Scaling with HAProxy
When a single cloud instance reaches compute or memory saturation, horizontal scaling becomes mandatory. **HAProxy** (High Availability Proxy) is the gold standard for high-performance TCP and HTTP load balancing, powering some of the highest-traffic architectures in the world.
In this architecture guide, we deploy HAProxy on a dedicated gateway node to distribute traffic across multiple backend application servers with automated health checks and session persistence.
Step 1: Install HAProxy on the Gateway Node
sudo apt update && sudo apt install -y haproxy
sudo systemctl enable --now haproxy
Step 2: Configure Layer 7 Frontend and Backend Pools
Edit `/etc/haproxy/haproxy.cfg`:
sudo nano /etc/haproxy/haproxy.cfg
Append the following frontend and backend definitions:
global
log /dev/log local0
log /dev/log local1 notice
maxconn 50000
user haproxy
group haproxy
daemon
defaults
log global
mode http
option httplog
option dontlognull
timeout connect 5000ms
timeout client 50000ms
timeout server 50000ms
# Public Frontend (Port 80 / 443)
frontend http_front
bind *:80
# Redirect HTTP to HTTPS
redirect scheme https code 301 if !{ ssl_fc }
frontend https_front
bind *:443 ssl crt /etc/ssl/certs/cloud-bundle.pem alpn h2,http/1.1
mode http
# Route traffic to application backend pool
default_backend app_cluster
# Backend Application Servers
backend app_cluster
mode http
balance roundrobin
option forwardfor
# Active Health Checks (every 2 seconds, 3 failed checks mark node down)
server node1 10.0.0.101:8080 check inter 2000 rise 2 fall 3
server node2 10.0.0.102:8080 check inter 2000 rise 2 fall 3
server node3 10.0.0.103:8080 check inter 2000 rise 2 fall 3 backup
Step 3: Enable the HAProxy Live Telemetry Dashboard
HAProxy provides an integrated status dashboard to observe backend latency, active connections, and node health:
listen stats
bind *:8404
stats enable
stats uri /monitor
stats refresh 5s
stats auth admin:SuperSecretDashboardPassword2026!
Validate and restart the service:
sudo haproxy -c -f /etc/haproxy/haproxy.cfg
sudo systemctl restart haproxy
Accessing `http://your-gateway-ip:8404/monitor` gives you real-time visual telemetry on all backend instances.