Skip to content

Database health

Gate readiness on a real round-trip to the database — one module import wires the indicator.

The readiness probe should fail when the database is unreachable. NestRS ships a SeaORM-backed indicator that runs DatabaseConnection::ping and plugs straight into nest-rs-health’s indicator registry — no glue code, no probe handler to write.

Import SeaOrmHealthModule alongside HealthModule:

apps/api/src/module.rs
use nest_rs::core::module;
use nest_rs::health::HealthModule;
use nest_rs::seaorm::{SeaOrmDatabaseModule, SeaOrmHealthModule, SeaOrmModule};
#[module(
imports = [
SeaOrmModule::for_root(None),
SeaOrmDatabaseModule,
SeaOrmHealthModule,
HealthModule,
],
)]
pub struct AppModule;

That’s it. Importing the module registers SeaOrmHealthIndicator as both a readiness and a startup indicator — HealthModule discovers them through the inventory seam and mounts the probes automatically.

Two endpoints exit the box with the database wired in:

EndpointIndicator runsFailure
GET /health/readySeaOrmHealthIndicator::db503 while unreachable
GET /health/startupSeaOrmHealthIndicator::db_ready503 until first ping succeeds

The liveness probe (GET /health/live) deliberately does not depend on the database — a brief DB outage should not kill the pod.

Terminal window
$ curl -s http://localhost:3000/health/ready
{"status":"up","info":{"db":{"name":"db","status":"up"}},"error":{},
"details":{"db":{"name":"db","status":"up"}}}

When the ping fails the indicator moves from info to error, the overall status switches to down, and the response is a 503. The body carries the fixed reason "check failed" — never the DbErr, which would put a DSN or an internal hostname on a routinely unauthenticated endpoint. The real error goes to the log instead: warn on nest_rs::health, with indicator, kind and error as fields. Indicators is the reference for that split; the shape itself is on Health.

  • Database — the slice the indicator hangs off.
  • Repo and executor — the DatabaseConnection the indicator pings.
  • Health — the indicator registry, the probe endpoints, custom indicators for other dependencies.