Module 6 · Reliability and infrastructureLesson 64 of 886 minIntermediate

Health checks

Health checks let load balancers and orchestrators find broken or not-yet-ready instances and route around them automatically.

Try it

Play "Liveness" and watch a hung server get removed and restarted. Then "Readiness", and finally "Shallow vs deep".

A load balancer or orchestrator can't fix problems it can't see. Health checks are small endpoints, like /healthz, that it polls every few seconds.

Liveness and readiness

Kubernetes made this split popular, and it's useful everywhere:

Liveness: "is this process fundamentally working?"

  • Fails if the app is deadlocked or stuck.
  • Action: restart it.
  • Keep it simple: can the process respond at all?

Readiness: "can this instance handle traffic right now?"

  • Fails while starting up, warming caches, or when temporarily overloaded.
  • Action: stop routing requests to it, but leave it running.

There's also startup checks for slow-starting apps, so liveness doesn't kill them before they've finished booting.

Thresholds

Checks run every few seconds, and one failure usually isn't enough. "Remove after 2 failures, add back after 3 successes" avoids flapping. Faster detection means more false alarms; slower means more user errors during a real failure.

Shallow vs deep checks

  • A shallow check only proves the process answers. It can report healthy while every real request fails because the database is down.
  • A deep check also tests key dependencies (database, cache).

Deep checks have a trap: if all servers share a database and it blips, every server fails its check and the load balancer removes all of them, turning a partial outage into a total one. Common practice: liveness stays shallow; readiness checks only things this instance can fix by restarting or waiting; dependency health goes to monitoring and alerts instead.

Don't forget

  • Health endpoints should be cheap and unauthenticated (but not reveal secrets).
  • Health checks also drive zero-downtime deploys: new instances only get traffic once ready, old ones are drained before stopping.

Quick check

A new server is starting and needs 30 seconds to load data before it can serve requests. Which check stops traffic reaching it too early?