Skip to content

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

javascript
// 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

  1. The service exposes a health check endpoint (e.g., /health).
  2. A load balancer or orchestrator calls the endpoint periodically.
  3. If the response is healthy (200), traffic is sent to the service.
  4. 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.

View errors

← Back to glossary