Skip to content

Health checks and graceful shutdown

Introduction

Expose liveness and readiness probes so the platform knows whether traffic can be accepted, and finish in-flight work before shutdown.

Why use it

  • Automatic recovery: when a process hangs, the platform sees the check fail and restarts it.
  • No half-ready traffic: while starting up or before the database is connected, user requests are not sent to it.
  • Releases do not drop requests: when shutting down the old version, finish in-flight requests first so users do not notice.

Do not confuse the two probes

A probe is a check request the platform sends on a schedule.

Probe Question On failure What to check
Liveness Is the process alive and not hung? The platform restarts it Only itself—do not check the database
Readiness Can it handle requests right now? Temporarily stop sending traffic; do not restart Critical dependencies such as the database and cache

How to do it

  1. Expose two endpoints, such as /health/live and /health/ready, returning 200 when healthy.
  2. Point platform probes at them in Docker, Kubernetes, and similar.
  3. Implement graceful shutdown: on a stop signal (SIGTERM), first mark as “not ready” and stop taking new requests, wait for in-flight requests to finish (with a cap, such as 30 seconds), then exit.
  4. The platform’s “force-kill wait” must be longer than your graceful-shutdown window.

Component comparison

Built-in framework health checks (ASP.NET Core Health Checks)

Built into the frameworkOpsLow

ASP.NET Core's built-in health check mechanism: register a few checks (such as whether the database is reachable), then expose them as HTTP endpoints for the platform to call.

Best forProjects using ASP.NET Core that want the standard way to separate liveness and readiness probes.

Avoid whenThe project is Python or on another non-.NET stack.

Pros

Built in with a standard style, and different endpoints can be given different checks (separating liveness from readiness)

The community has ready-made check packages for databases, caches, and message queues

Works naturally with the Host's graceful shutdown

Cons

Only applicable to C# / ASP.NET Core

Checks that are too heavy (running complex SQL every time) put extra pressure on dependencies

Returns only a simple status by default; a nicer UI needs another package or your own code

Hand-written /healthz endpoint

Hand-rolledOpsLow

Write a tiny endpoint yourself that returns 200 to mean "I am alive", adding a database check when needed, usually paired with a readiness endpoint.

Best forPython services or small projects that only need the most basic "is the process alive" check.

Avoid whenThere are many services needing a unified standard, or a built-in framework solution is already available.

Pros

A few lines of code are enough, and any language and framework can use it

You fully decide what is checked and what is returned

It adds no extra dependency, so a small service can adopt it easily

Cons

There is no shared standard, so each service is easy to write differently

A database check inside the liveness probe restarts everyone when the database blips

If a dependency hangs you must add your own timeout, or the endpoint hangs with it

Container HEALTHCHECK and Kubernetes probes

Built into the frameworkOpsMedium

The platform checks actively: Docker's HEALTHCHECK runs a command periodically to judge container state, and Kubernetes liveness and readiness probes periodically call your health endpoint.

Best forServices already deployed with Docker or Kubernetes that want automatic restarts and removal of failed instances.

Avoid whenRunning directly on virtual machines without containers; use a process supervisor or the load balancer's own checks instead.

Pros

A failed liveness check restarts the process, and a failed readiness check pulls it out of traffic

It does not depend on the language: a health endpoint or a command is enough

The configuration is usually a few lines of YAML or a Dockerfile instruction

Cons

The platform only probes and acts; you still have to provide the health endpoint

A poorly chosen interval or timeout will kill a process that is only starting slowly

A HEALTHCHECK marked unhealthy does not restart the container by itself

Hand-written /healthz probe

Open-source libraryOpen sourceOpsLow

Expose /healthz on Axum, and check dependencies such as the database from the readiness probe.

Best forHealth checks and probes for any Axum project.

Avoid whenA service mesh already probes the process and you do not need application-level checks.

Pros

No extra framework; paths and checks are fully under your control

Liveness and readiness can be two routes

Maps directly to a Kubernetes httpGet probe

Cons

Database and Redis checks are hand-written

A heavy check slows the probe

Metrics need a separate prometheus exporter

Official docs ↗

NestJS Terminus

Open-source libraryOpen sourceOpsLow

NestJS's official health check module, with built-in common checks for databases, HTTP, memory, and more.

Best forHealth checks for any NestJS project.

Avoid whenNon-NestJS projects (a hand-written /healthz is enough).

Pros

Officially maintained and integrates smoothly with NestJS

Built-in checks for common dependencies

Output format is compatible with Kubernetes probes

Cons

Only applicable to NestJS

Too many checks slow down the probes

You must separate liveness from readiness yourself

Official docs ↗

Go hand-written /healthz probe

Open-source libraryOpen sourceOpsLow

Expose /healthz and /readyz with the standard library or chi/Gin, and check dependencies such as the database from the readiness probe.

Best forHealth checks and probes for any Go project.

Avoid whenA service mesh already probes the process and you do not need application-level checks.

Pros

No extra framework; paths and checks are fully under your control

Liveness and readiness can be two routes

Maps directly to a Kubernetes httpGet probe

Cons

Database and Redis checks are hand-written

A heavy check slows the probe

Metrics need a separate Prometheus client

Official docs ↗

Checklist

  • Separate liveness and readiness endpoints exist
  • The liveness probe does not depend on external services
  • The readiness probe covers critical dependencies such as the database
  • On SIGTERM, stop taking new requests first, then finish in-flight work
  • The platform force-kill wait is longer than the graceful-shutdown window
  • Health endpoints expose no internals and do not require login