A health check monitors the condition and status of backend servers that communicate with a load balancer. Since load balancers rely on functional pools of backend resources, maintaining visibility into the health of those servers is essential to effectively routing client traffic.
Accordingly, you can use health checks to gather information on resource usage. This includes available memory, CPU load, and overall capacity. The result of this health check can influence how traffic is diverted and is typical in environments where redundancy is established. When a server does fail, the remaining servers pick up the slack to avoid downtime and application performance degradation.
How do health checks work?
Load balancers have various built-in mechanisms that enable health checking. First come active health checks, which poll your servers at set intervals to attempt a connection (via TCP or HTTP). These typically occur every couple of seconds. If the server fails to send a response back—either once or after a configured number of times—then the server is removed from the pool.
Next come passive health checks, which instead monitor traffic behavior, monitor TCP connections, and watch for response errors. Once a certain number of errors accumulate, the server is deemed faulty and removed. Passive health checks will monitor for response codes that indicate a server problem (such as 5xx codes or connection failures). Plus, these health checks often (if not always, in some cases) occur simultaneously with active health checks.
Finally, agent health checks, which leverage software running directly on the server (outside of the application itself), gather data on the server's vital signs. This can include CPU load, memory pressure, number of connections, and more. The agent program can access the system in its entirety, so no performance stone remains metaphorically unturned. Aside from sharing a simple UP or DOWN status, an agent health check can alter traffic volumes, trigger server maintenance mode, or alter the total number of allowed concurrent client connections.
Health checks are typically defined in the load balancer's configuration. They're highly customizable in many cases and boost observability into systems that might otherwise seem like black boxes.
Does HAProxy support health checks?
Yes! HAProxy products support all three types of health checks defined above. We offer rich configuration options to help you establish granular, multi-layered health checking directly within the HAProxy config file. To learn more, check out our blog on enabling health checks or dive into our health check documentation.