A common setup: the app exposes /health, and that endpoint runs SELECT 1 against the database so the load balancer only sends traffic to instances that can really serve requests. This looks careful. Then the shared database slows down for a minute, and the load balancer marks every instance unhealthy at once, including the ones that could still serve cached pages, static assets, or anything that never touches the database. The question to ask about any health check is what it does when a dependency is slow rather than dead.
The terms come up throughout, so here they are first. A shallow health check confirms the process is running, listening on its port, and able to answer a basic request, usually with an HTTP 200 OK. A deep health check also probes external dependencies such as the database, a cache, or another API before it answers. The Safeguard write-up on how health checks cascade uses these same definitions.
What the health checker does on every probe
A load balancer health checker is a small loop that runs per target. Every interval it opens a TCP connection to the instance, sends an HTTP request to the configured path, and starts a timer. If a response with an accepted status code arrives before the timeout, the probe counts as a success. A refused connection, a reset, a wrong status code, or a response that never arrives inside the timeout all count as a failure.
One failed probe does not change anything. The checker keeps a counter per target. When consecutive failures reach the unhealthy threshold, the target moves from healthy to unhealthy and stops receiving new requests. When consecutive successes reach the healthy threshold, it moves back. Kubernetes probes follow the same pattern, with periodSeconds, timeoutSeconds, and failureThreshold as the knobs.
As an illustrative example: with a 10 second interval, a 5 second timeout, and an unhealthy threshold of 3, a target that stops answering is pulled after roughly 30 seconds. Nothing in that state machine knows why the probe failed. A crashed process and a slow database query produce the same result.
What a stalled database does to a deep check
A database that is down and a database that is stalled behave very differently from the app's side.
When the database is down, the connection attempt usually fails quickly with "connection refused" or a fast network error. The deep check returns an error status within milliseconds. That is a clean failure, and the checker counts it.
When the database is stalled, for example because of lock contention, saturated disk I/O, or a long-running query holding resources, connections are still accepted. Queries just don't finish. The health handler then goes through these steps:
- The probe request arrives and the handler asks the connection pool for a database connection.
- Real user traffic is also stuck waiting on the slow database, so the pool may already be empty. The handler waits for a connection to be returned.
- If it gets a connection, it sends
SELECT 1, which waits behind whatever is slowing the server. - The load balancer's timer expires first. It closes its side and records a failure. The handler may still be holding a worker thread and a pool slot after the prober has given up.
The health check has now become extra load on the struggling database. Every load balancer node probes every instance, so the number of health queries grows with both counts. Those queries compete for the same pool slots that real requests need.
Why every instance fails in the same window
If one instance has a bad disk, its deep check fails and the others pass. That case is what health checks are meant for: the load balancer drains the broken instance and the rest carry on.
A shared database breaks that assumption. Every instance asks the same database the same question, so every instance gets the same slow answer. The probes are not synchronized to the second, but they fall within a few intervals of each other, so all failure counters reach the threshold in the same window. The load balancer then has zero healthy targets.
What happens next depends on the product. Some load balancers fail open: AWS documents that an Application Load Balancer routes to all targets when every target in a target group is unhealthy, on the theory that a fleet-wide failure is more likely a health check problem than a real one. Many others serve errors instead. A Kubernetes Service whose pods all fail readiness has no ready endpoints, and HAProxy typically answers with a 503 when a backend has no servers up. Either way, the requests that never needed the database fail along with the rest.
The outcome is worse when the deep check is wired into a Kubernetes liveness probe instead of a readiness probe. A readiness failure removes the pod from traffic. A liveness failure restarts the container. A slow database then makes the cluster restart every pod, which discards warm caches, triggers startup work, and opens a fresh set of database connections when the database recovers. That reconnect burst can push the database back over the edge.
This also explains a common confusing ticket. The customer sees "all targets unhealthy" in the load balancer console and assumes the web servers died. A support engineer should first check whether the health endpoint touches a shared dependency, and if it does, look at that dependency before touching the instances.
Choosing what the endpoint should test
A useful rule of thumb: a health check should test what removing or restarting this instance would fix. Removing an instance only helps if the problem lives on that instance. If every instance shares the dependency, pulling instances cannot help, so that dependency does not belong in the check that drives routing.
In practice, that usually splits like this:
- Good candidates: the process is up and its request loop answers, configuration loaded, local disk writable if the app needs it, and anything per-instance, such as a local sidecar or a cache running on the same host.
- Usually keep out: the shared primary database, a shared Redis cluster, third-party APIs, and anything else every instance talks to.
Shared dependencies still need watching, just not through routing. Monitor them directly and alert on them. Let the app degrade per route: return a 503 or a cached response for pages that need the database, and keep serving the ones that don't. Adrian Hornsby's resilient architecture patterns cover this trade-off. If your monitoring sits on the same infrastructure as the app, separating health checks from app infrastructure is a related problem worth reading about.
Some middle ground is reasonable. A readiness check can confirm the database once at startup, so a new instance doesn't take traffic before it can connect, and then fall back to local checks. A deep status endpoint can exist for dashboards and humans, reporting each dependency in the response body, as long as the load balancer is not pointed at it. If you do keep a dependency check in the routing path, run it in the background on its own short timeout, cache the result, and have the endpoint return the cached value. The probe then never blocks on the database.
Checking your own setup
Start by timing the endpoint from the instance itself. A shallow check should answer in milliseconds and should stay fast when the database is slow:
curl -s -o /dev/null -w '%{http_code} %{time_total}
' http://127.0.0.1:8080/health
Run it a few times during normal load and compare the time against the load balancer's configured timeout. If the endpoint's time rises with database latency, the check is deep, whatever its name says. Next, read the handler code or the framework's health module configuration. Many frameworks add database and cache checks to a default health endpoint automatically, so a check that looks shallow can be deep by default.
On Kubernetes, keep liveness and readiness on separate paths, so a restart decision never depends on the database. The timing values below are illustrative:
livenessProbe:
httpGet:
path: /livez
port: 8080
periodSeconds: 10
timeoutSeconds: 2
failureThreshold: 3
readinessProbe:
httpGet:
path: /readyz
port: 8080
periodSeconds: 5
timeoutSeconds: 2
failureThreshold: 3
Here /livez should only confirm that the process can answer. /readyz can include per-instance readiness, such as startup having finished. For a non-Kubernetes load balancer, find the same values in its target group or backend settings: the path, interval, timeout, and thresholds. Then work out how many seconds of database slowness it takes to empty the pool of healthy targets.
The practical test is short. For every dependency your health endpoint touches, ask whether all instances share it and what the endpoint does when it stops answering without failing. If all instances share it, take it out of the routing check, monitor it on its own, and let individual routes degrade when it slows down. A slow database will still hurt, but it will hurt only the requests that need it.