Health Checks

Built-in health check endpoints for container orchestration (Kubernetes, Docker Compose, etc.).

Endpoints

EndpointPurposeUse Case
GET /healthBasic healthLoad balancer
GET /healthzDetailed healthKubernetes liveness
GET /readyReadinessKubernetes readiness

GET /health

Basic liveness check — confirms the server is responding. Response (200):
{
  "status": "ok",
  "timestamp": "2025-01-15T10:30:00Z"
}
Response (503 if server is shutting down):
{
  "status": "shutting_down",
  "timestamp": "2025-01-15T10:30:00Z"
}

GET /healthz

Detailed liveness check with version info. Response (200):
{
  "status": "ok",
  "version": "1.0.0",
  "uptime": 86400,
  "timestamp": "2025-01-15T10:30:00Z"
}

GET /ready

Readiness check — confirms all dependencies are available. Response (200):
{
  "status": "ready",
  "checks": {
    "mongodb": {
      "status": "ok",
      "latency": 2
    },
    "redis": {
      "status": "ok",
      "latency": 1
    }
  },
  "timestamp": "2025-01-15T10:30:00Z"
}
Response (503 if not ready):
{
  "status": "not_ready",
  "checks": {
    "mongodb": {
      "status": "ok",
      "latency": 2
    },
    "redis": {
      "status": "error",
      "error": "connection refused"
    }
  },
  "timestamp": "2025-01-15T10:30:00Z"
}

Kubernetes Configuration

livenessProbe:
  httpGet:
    path: /healthz
    port: 3100
  initialDelaySeconds: 10
  periodSeconds: 15
  failureThreshold: 3

readinessProbe:
  httpGet:
    path: /ready
    port: 3100
  initialDelaySeconds: 5
  periodSeconds: 10
  failureThreshold: 3

Docker Compose

services:
  bun-core:
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:3100/health"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 10s

Error Responses

If a dependency is down:
{
  "status": "not_ready",
  "checks": {
    "mongodb": {
      "status": "error",
      "error": "connection timeout"
    }
  }
}
HTTP status: 503 Service Unavailable