Health Check
In one line
A health check is a periodic test that verifies a service is running and ready to serve requests.
In simple words
A health check is a simple test that asks "is this service healthy?" It is usually an HTTP endpoint (like /health or /healthz) that returns a 200 status code if the service is fine and a non-200 code (or no response) if something is wrong.
Health checks are used by load balancers, orchestrators (Kubernetes), and monitoring systems to decide whether to send traffic to a service. If the health check fails, the service is removed from the load balancer's rotation until it recovers.
There are typically two types: liveness (is the service running?) and readiness (is the service ready to handle requests?). A service might be running but not ready — for example, it might still be loading data or waiting for a database connection.
Example
// Express.js health check endpoint
app.get("/health", (req, res) => {
if (db.isConnected()) {
res.status(200).json({ status: "healthy" });
} else {
res.status(503).json({ status: "unhealthy" });
}
});This endpoint returns 200 if the database is connected (healthy) and 503 if not (unhealthy).
How it works
- The service exposes a health check endpoint (e.g., /health).
- A load balancer or orchestrator calls the endpoint periodically.
- If the response is healthy (200), traffic is sent to the service.
- If unhealthy (non-200), traffic is stopped until the service recovers.
Common confusions
Confused with: Liveness Probe
The difference: A health check is a general concept; a liveness probe is Kubernetes' specific implementation of a health check that determines if a container should be restarted.
Related terms
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.