EMZETT.
Login

Health checks and graceful shutdown

In short: A health check is an endpoint that reports whether a service is healthy. Graceful shutdown means letting a service finish running requests before it stops.

In more detail: Load balancers and orchestrators (for example Kubernetes) query the health check regularly. If a server does not answer, it receives no more traffic or is restarted.

In Depth

  • Liveness: Is the process running at all? If not, restart.
  • Readiness: Is the service ready for traffic (database connected, cache warmed)? If not, take it out of rotation temporarily.
  • Keep it simple: A health check should be fast and not generate load itself.
  • Graceful shutdown: On the SIGTERM signal, accept no new requests, finish running ones, close connections, then exit.
  • Time limit: After a deadline (for example 30 seconds) SIGKILL follows and cannot be caught.

See also: Sticky sessions