HAProxy
A high-performance TCP and HTTP load balancer known for reliability, fine-grained health checks and detailed stats.
Intermediate · about 5 hours · difficulty 3/5
Learn first: How Web Servers Serve Traffic
HAProxy focuses on load balancing and proxying rather than serving files. It is used at very high traffic volumes and is a good choice when you need precise control over balancing, health checks and connection handling.
What to learn
- Config sections:
global,defaults,frontend(where traffic arrives),backend(pools of servers), andlisten(both in one). mode tcpfor layer 4 andmode httpfor layer 7 with ACLs to route by host, path or header.- Balancing algorithms (
roundrobin,leastconn,source) and active health checks (option httpchk). - Stick tables for rate limiting and session persistence.
- The stats page and runtime API for draining servers during deploys.
Where it fits
Great in front of databases (TCP), for large-scale HTTP balancing, and as a Kubernetes ingress option. It does not serve static sites, so it is often paired with a web server or CDN.
Good enough to move on: you can balance HTTP across a pool with health checks, route two hostnames to different backends, and drain a server via the runtime API.
Key concepts
- frontend and backend sections
- TCP vs HTTP mode
- ACL routing
- Health checks
- Stick tables
- Stats page and runtime API
Other options for this step
- Nginx: The most widely deployed web server and reverse proxy; learn its config model and the handful of directives that cover most real setups.
- Caddy: A modern web server with automatic HTTPS and a very short config format, great for small teams and simple deployments.
- Apache HTTP Server: The long-standing web server still common in legacy stacks, shared hosting and PHP applications.
Mini project
Put HAProxy in front of three app containers with leastconn balancing and HTTP health checks, expose the stats page, and drain one server during a simulated deploy.
Check yourself
When would you choose mode tcp over mode http in HAProxy?
Free resources
- HAProxy documentation (haproxy.org)
- HAProxy blog and tutorials (HAProxy Technologies)