All guides
Home Glossary HAProxy
Term

HAProxy

HAProxy is a high-performance, open-source software solution for TCP/HTTP load balancing and proxying.

HAProxy is a high-performance, open-source software solution for TCP and HTTP load balancing and proxying. Acting as a reverse proxy gateway between incoming client requests and backend application servers, it distributes network traffic across multiple nodes to maximize throughput, minimize response times, and eliminate single points of failure. High-traffic platforms such as GitHub, Reddit, and Stack Overflow rely on HAProxy to maintain high availability at scale.

How it works

HAProxy uses an event-driven, non-blocking I/O architecture capable of handling tens of thousands of concurrent connections with minimal CPU overhead. Its configuration is divided into frontend sections, which define the IP addresses and ports accepting client connections, and backend sections, which group the target application servers. When a request arrives, the engine evaluates it against Access Control Lists (ACLs) and forwards it to the appropriate server pool using algorithms such as round-robin or least connections.

  • Layer 4 and Layer 7 Routing: Forward raw TCP packets at the transport layer or inspect HTTP headers, cookies, and URLs at the application layer to make smart routing decisions.
  • SSL/TLS Termination: Decrypt incoming HTTPS traffic at the edge so backend application servers do not spend CPU cycles on cryptographic handshakes.
  • Active Health Checks: Periodically probe backend nodes and automatically remove unresponsive servers from rotation until they recover.
  • Session Persistence: Route returning visitors to the same backend instance using HTTP cookies or source IP hashing when applications store state locally.

Example

A typical configuration defines an HTTP frontend listening on port 80 and a backend pool of two web servers with active health checks enabled:

frontend web_gateway
    bind *:80
    mode http
    default_backend app_servers

backend app_servers
    mode http
    balance roundrobin
    option httpchk GET /health
    server web1 10.0.1.10:8080 check
    server web2 10.0.1.11:8080 check

In this setup, HAProxy checks the /health endpoint on both backend nodes and alternates incoming HTTP traffic between web1 and web2.

What matters when choosing a server or hosting

Because HAProxy is heavily network- and CPU-bound rather than disk-bound, prioritize high single-core clock speeds, low-latency network interfaces, and generous bandwidth allowances over large local storage. If you run SSL termination at high connection rates, modern processors with AES-NI hardware acceleration significantly improve TLS handshake performance. Additionally, deploying two HAProxy instances across separate availability zones with a floating IP or DNS failover ensures the load balancer itself does not become a single point of failure.

Common mistakes

  • Using default TCP checks for HTTP apps: A basic port check confirms a socket is open, not that the application is functioning. Always configure option httpchk to verify an actual HTTP status code.
  • Omitting connection timeouts: Failing to set timeout connect, timeout client, and timeout server leaves stalled connections open, eventually exhausting file descriptors and memory.
  • Ignoring forwarded client headers: Without option forwardfor, backend web servers see the load balancer's internal IP address instead of the real client IP in access logs and rate limiters.

FAQ

Does HAProxy work as a web server?

No. HAProxy is strictly a reverse proxy and load balancer. It cannot serve static files directly from disk or execute application code; it must forward requests to dedicated web or application servers like Nginx, Apache, or Node.js.

What is the difference between Layer 4 and Layer 7 load balancing in HAProxy?

Layer 4 (mode tcp) forwards raw TCP streams based purely on IP addresses and ports without inspecting packet contents. Layer 7 (mode http) parses the HTTP protocol, enabling URL-based routing, header modification, and cookie-based session stickiness.

Can HAProxy reload its configuration without dropping active connections?

Yes. HAProxy supports seamless reloads by starting a new worker process with the updated configuration while allowing the old process to finish serving existing connections before exiting.

All glossary terms

Glossary

Related terms

Full glossary

New guides every week.

A digest of the best pieces on servers, VPN and self-hosted software. No ads, no spam.

1 email a weekOne-click unsubscribeRU · EN
Only slipjar.app articles, nothing else.