What it is
A health check is a small, repeated test that tells a load balancer, orchestrator or service registry whether an instance should get traffic or be restarted. Active checks send probes on a schedule (a TCP connect, an HTTP GET /healthz, a gRPC health call). Passive checks watch real traffic and count errors or timeouts per backend.
Why it exists
Instances crash, hang, run out of disk or get stuck during startup. Without a check, a balancer keeps sending a share of traffic to a dead instance forever. Health checks close that loop automatically, so that redundancy turns into availability without a human pulling the broken server out.
How it works
Probes and thresholds. Each balancer node probes each backend every interval. A probe fails if it errors or does not answer within the timeout. After unhealthy threshold consecutive failures the backend is marked unhealthy and removed from rotation; after healthy threshold consecutive successes it is put back. Thresholds above one prevent a single lost probe from ejecting a server, and stop a flapping server from bouncing in and out.
Detection time. From a crash to ejection takes up to one interval (until the next probe) plus threshold − 1 more intervals. With a 1 s interval and a threshold of 3, that is 2–3 s; with a 30 s interval and a threshold of 2 (defaults in some managed balancers are in this range), close to a minute. Requests routed to the instance during that window fail or time out.
Liveness, readiness, startup. Kubernetes separates three probes, and the split is useful anywhere:
- Liveness: is the process wedged? Failing it gets the container restarted.
- Readiness: should this instance receive traffic right now? Failing it removes the Pod from the Service's endpoints; nothing is restarted.
- Startup: holds off the other two while a slow-starting app initialises.
Shallow and deep checks. A shallow check answers from the process itself. A deep check also calls dependencies (database, cache, downstream APIs). Deep checks can find more problems, but every instance shares those dependencies.
Passive checks / outlier detection. Proxies such as Envoy and NGINX can eject a backend after consecutive 5xx responses, connection failures or (in some products) high latency on real traffic, then bring it back after a cool-off. This catches failures that probes do not exercise.
When to use it
Always, for anything behind a balancer or managed by an orchestrator. Use readiness checks for warm-up (loading caches, JIT, model weights) and for graceful shutdown: fail readiness, wait for the balancer to notice, drain in-flight requests, then exit.
When not to
- Do not use liveness checks for things a restart cannot fix (a dependency being down): restarts make it worse.
- Do not put shared dependencies in a check that decides routing for every instance.
- Do not rely on probes alone where gray failures (slow, partly broken instances) matter; add passive checks.
Trade-offs
| Choice | You gain | You pay |
|---|---|---|
| Short interval | Smaller detection gap | Probe load (balancer nodes × backends × rate), more sensitivity to blips |
| Unhealthy threshold of 1 | Fastest ejection | Healthy servers ejected on one slow probe or GC pause |
| High healthy threshold | No flapping | Recovered capacity returns later |
| Deep check | Catches broken dependency wiring per instance | One shared failure ejects every instance |
| Passive checks | Sees real errors and gray failures | Needs traffic; can eject on errors caused by bad requests |
Alternatives
- Client-side health in service meshes and gRPC clients: each client tracks backend errors itself.
- Service registry heartbeats (Consul, etcd leases): instances renew a lease; when they stop, they are deregistered.
- Synthetic monitoring checks the user journey end to end; it alerts humans rather than routing traffic.
Failure modes
- Detection gap: errors for interval × threshold after every crash.
- Gray failure: an instance is alive and answers probes but serves real requests slowly or wrongly. A liveness-style check keeps it in rotation.
- Cascading ejection: a deep check against a shared database fails on every instance at the same time; the balancer has nothing left and the outage is total, even for requests that did not need the database.
- Restart loops: a liveness probe that fails under load restarts busy instances, which pushes their load onto the rest, which then fail their probes too.
- Lying endpoint:
/healthzreturns 200 from a thread that is fine while the request threads are deadlocked.
In production
Keep liveness trivial (the process can answer). Make readiness about the instance's own ability to serve: started, warmed up, not draining, local resources fine. Leave shared dependencies out of both, and handle them in the request path with timeouts, circuit breakers and degraded responses. Know your balancer's last-resort behaviour: AWS Application and Network Load Balancers route to all targets when every target is unhealthy (fail open), and Envoy ignores health status when the healthy share drops below its panic threshold (50% by default). Add outlier detection with a cap on how many hosts can be ejected at once.
Common misconceptions
- "200 from /healthz means the instance is fine." It means the health handler ran. Slow disks, exhausted pools or deadlocked worker threads may not show up.
- "A more thorough check is always better." Including shared dependencies couples every instance's fate to them.
- "Faster probes fix gray failures." A probe that already succeeds succeeds more often.
- "Liveness and readiness are the same probe with different names." One restarts, the other routes; using one for the other causes restart storms or keeps broken instances in service.
Interview angle
When you place a load balancer, say how it learns about failures: probe type, interval, thresholds and the resulting detection time. Distinguish liveness and readiness, explain how draining uses readiness during deploys, and point out the deep-check trap with a shared database. Mentioning passive checks or outlier detection for gray failures, and fail-open behaviour when everything looks unhealthy, shows production experience.
Model assumptions
This lesson runs the simulation engine for traffic, crashes and ejection. Arrivals are Poisson; each app server has 8 workers, a 40 ms mean service time (lognormal, cv 0.35) and room for 16 waiting requests; reads go through a shared cache with a fixed 80% hit ratio and to a 20-connection database on a miss. The balancer probes every 1 s (3 failures eject, 2 successes restore), later every 250 ms (2 failures eject). Probe packets are drawn slower than the modelled 5 ms hop so they are visible. The engine's probes only see whether a node is up or down: a degraded (slow) node passes them, like a liveness check. Readiness is shown by removing the server from the balancer's backend list, and a failing deep check by every app server reporting down to the balancer; neither is a separate probe type in the model. Numbers are illustrative, not benchmarks.