Health Checks

Designing Useful Health Check Endpoints

By ShakeScan Editorial Team · · 5 min read

A health check endpoint is a small URL that a service exposes so that other systems can ask a simple question: are you working? Load balancers use it to decide where to send traffic. Orchestrators use it to restart failed instances. Monitoring tools use it to raise alerts. Because so many automated decisions depend on the answer, a poorly designed health check can do real harm.

A check that always says "OK" hides outages. A check that is too strict can cause healthy servers to be pulled out of service, turning a minor dependency hiccup into a full outage. This article explains how to design checks that are honest, cheap and safe.

What a Health Check Is For

Before writing code, decide who will consume the result and what they will do with it. Different consumers need different answers:

  • A load balancer needs to know whether this instance should receive requests right now.
  • A process supervisor or orchestrator needs to know whether the process is stuck and should be restarted.
  • A monitoring system wants to know whether the service is delivering value to users.
  • A human debugging an incident wants detail about which parts are failing.

Trying to serve all of them with one endpoint leads to compromises. Splitting the checks by purpose is usually cleaner.

Liveness, Readiness and Startup

Three related concepts, popularized by container orchestration, are worth separating.

Liveness

Liveness asks: is the process alive and able to make progress? It should be very simple. If the application is deadlocked or in an unrecoverable state, the check fails and the process is restarted. A liveness check should not test external dependencies. If the database is down, restarting your application will not fix it, and a restart loop could make things worse.

Readiness

Readiness asks: is this instance ready to accept traffic? It may fail while the service is warming caches, loading configuration or temporarily overloaded. When it fails, the instance is removed from the pool of servers receiving requests, but it is not restarted. When it passes again, traffic returns. This is the right place to consider whether essential dependencies are reachable.

Startup

Some applications take a long time to start. A startup check gives them extra time before liveness checks begin, preventing an orchestrator from killing a process that is simply still booting.

What to Check and What Not to Check

Decide carefully which dependencies belong in a readiness check.

Include things your service cannot function without, such as its primary database or a required internal service. If those are unavailable, receiving traffic would only produce errors.

Be cautious with optional dependencies. If a recommendation engine is down but your page still works without it, failing the whole check will remove healthy servers for no reason. Report the degraded state instead.

Avoid cascading failures. Suppose service A checks service B, which checks service C. A slowdown in C makes B fail, which makes A fail, and the whole chain disappears from rotation. Prefer shallow checks for the dependency chain, or use cached results and circuit breakers.

Keep checks cheap. They run often, from multiple callers. A health check that runs a heavy database query every few seconds creates its own load. Use lightweight operations, such as a simple connection test, and set timeouts shorter than the check interval.

Response Format

Keep it simple and predictable. The HTTP status code is the main signal:

  • 200 means healthy.
  • 503 means unhealthy or not ready.

Many teams also return a small JSON body with extra detail:

{
  "status": "degraded",
  "checks": {
    "database": "ok",
    "cache": "ok",
    "email_provider": "timeout"
  },
  "version": "2026.11.3"
}

A clear status field, per-component results and the running version make debugging far easier. Standardize the format across services so tools and people can read them the same way.

Avoid returning 200 with an error message in the body, since simple monitors only read the status code.

Separate Public and Internal Detail

A health endpoint that lists internal hostnames, software versions and dependency failures is a gift to an attacker. Decide what is safe to expose.

  • Keep the simple pass or fail endpoint reachable by load balancers and monitoring systems.
  • Restrict the detailed endpoint to internal networks or require authentication.
  • Do not include secrets, connection strings, stack traces or user data.
  • Do not allow the endpoint to trigger expensive operations on request.

Practical Design Tips

  • Use a dedicated path such as /healthz or /health/ready, and keep it stable.
  • Skip authentication on the basic check only if it exposes nothing sensitive, and restrict by network where possible.
  • Set sensible thresholds. Require several consecutive failures before taking action, so one slow response does not remove a server.
  • Use timeouts. A hung check should fail, not wait forever.
  • Do not log every check at normal level. The volume will drown out useful messages.
  • Include a graceful shutdown path. When the service is about to stop, make readiness fail first so that the load balancer drains traffic before the process exits.
  • Test the failure modes. Deliberately break a dependency in a test environment and confirm that your checks react the way you expect.

Synthetic Checks From Outside

Internal health checks tell you the process believes it is fine. They cannot tell you whether users can reach it. Complement them with external checks that behave like a user: request a real page, log in, complete a simple transaction. These catch problems in DNS, certificates, networking and the user journey that internal checks miss.

Frequently Asked Questions

Should a health check test the database?

A readiness check often should, using a lightweight query or connection test, because an instance without its database cannot serve useful requests. A liveness check should not, since restarting the application will not repair a database problem and may make the situation worse.

How often should health checks run?

Common intervals range from a few seconds to about half a minute, depending on how quickly you need to react. Shorter intervals detect failure sooner but add load and risk false alarms. Pair the interval with a failure threshold and timeout that suit your service.

Is a simple 200 response enough?

For liveness, often yes. For readiness and monitoring, a bare 200 can hide problems if it does not verify anything meaningful. Aim for a check that reflects the ability to do real work, while keeping it fast, cheap and safe against cascading failures.

Related reading