HAProxy
HAProxy is software that sits in front of a service and distributes incoming traffic across its servers. It can check whether each server is ready and stop sending new traffic to servers that fail those checks.
What HAProxy does
HAProxy is an open-source reverse proxy and load balancer. Imagine a web app running on two machines. Users connect to one public address rather than choosing a machine themselves. HAProxy accepts the traffic, picks an eligible server, and relays the response. You can then add capacity or take an instance out of rotation without asking clients to use a different address.
Connections versus requests
A frontend defines where HAProxy listens and how it routes incoming traffic. A backend defines a pool of servers, a balancing policy, and optional health checks. With equal server weights, round robin cycles through eligible servers. Least connections favors servers with fewer active connections, which can be useful when some connections last much longer than others.
In TCP mode (Layer 4), the unit of balancing is a connection. HAProxy can pass an encrypted TLS stream through to a server without decrypting it, but it cannot use the HTTP path inside that stream to route requests. In HTTP mode (Layer 7), HAProxy understands requests and can route /api and /images to different pools, even when they arrive over the same client connection. To inspect requests arriving over HTTPS, HAProxy terminates client TLS; the hop to the backend can use a separate TLS connection.
Example: keep unready instances out of rotation
defaults
mode http
timeout connect 3s
timeout client 30s
timeout server 30s
frontend web_in
bind :8080
default_backend web_nodes
backend web_nodes
balance roundrobin
option httpchk GET /ready
server web1 10.0.0.11:8000 check
server web2 10.0.0.12:8000 check
This example listens for plain HTTP on port 8080 and checks /ready on both servers. After enough consecutive failed checks, HAProxy stops selecting that server for new requests. A check that only opens a TCP connection would catch a closed port, but it would not catch an app that accepts connections while reporting that it cannot serve requests.
Where it fits and what interviewers ask
HAProxy is used at the edge for websites and APIs and internally for services that speak TCP. A common interview question is: “If a backend fails halfway through a request, will the client notice?” Potentially, yes. Health checks affect future routing; they do not move a request already in progress. Retrying also requires care: a server might have committed a write before its response was lost.
Another question is whether two backend servers make the setup highly available. They reduce the impact of a backend failure, but a lone HAProxy instance is still a single point of failure. A redundant design needs both multiple proxy instances and a way to direct incoming traffic to one that is still working.