Health check: testing whether a server is working
A health check is a periodic request sent to a server or endpoint to test whether it is working, so load balancers, DNS failover or monitoring can stop sending traffic to a failing target. A target is judged by response status and timing.
- A health check requests a path and judges the answer by status code and time.
- Thresholds prevent one failed request from removing a server.
- A check that is too shallow misses real failures. Too deep, and a dependency outage removes every server.
What do health check settings look like?
| Setting | Default | Meaning |
|---|---|---|
| Path | / | URL requested with HTTP GET |
| Interval | 30 seconds | Time between checks of one target (range 5 to 300) |
| Timeout | 5 seconds | No answer within this time is a failure (range 2 to 120) |
| Unhealthy threshold | 2 | Consecutive failures before the target is taken out of service |
| Healthy threshold | 5 | Consecutive successes before it is put back in service |
| Success codes | 200 | Response codes counted as healthy (200 to 499 allowed) |
Values from AWS health check documentation. Other products use different defaults.
How do you design a good health check endpoint?
- 01
Give it its own path
Use a dedicated path such as /health that is cheap to serve and not cached.
- 02
Decide how deep to check
A shallow check confirms the process answers. A deeper one also checks the database, but a database outage then marks every server unhealthy.
- 03
Return a clear status
Respond with 200 when healthy and a 5xx code when not, matching the success codes you configured.
- 04
Tune thresholds
Pick an interval and failure count that balance fast detection against flapping.
Common questions
What is the difference between a health check and uptime monitoring?
A health check runs inside your infrastructure, usually from a load balancer, to route traffic. Uptime monitoring runs from outside, from the visitor point of view, and alerts people. You want both, because internal checks can pass while the public site is unreachable.
How often should a health check run?
The AWS default is every 30 seconds with 2 failures needed to mark a target unhealthy, so a failing server can be removed in roughly a minute. Shorter intervals detect faster but add load and false positives.
What happens when all targets fail the health check?
It depends on the product. AWS load balancers fail open and send traffic to all targets regardless of health, so users may still get some responses. Check your product documentation before relying on that behavior.
Keep reading
Check your site from outside
Uptime checks run from 1 to 6 regions depending on plan, with alerts in one Attention queue.