alepha@docs:~/docs/guides/observability$
cat 2-health.md
1 min read
Last commit:

#Health Checks

Every production app needs a health endpoint. Load balancers, Kubernetes, and monitoring systems all need to know if your app is alive.

Alepha provides health endpoints out of the box.

#Basic Setup

typescript
1import { Alepha } from "alepha";2import { AlephaServerHealth } from "alepha/server-health";3 4const alepha = Alepha.create()5  .with(AlephaServerHealth);

This gives you two endpoints:

#/health - Detailed Health

Returns JSON with status and uptime:

json
1{2  "status": "ok",3  "uptime": 123454}

Use this for monitoring dashboards and detailed checks.

#/healthz - Simple Probe

Returns plain text:

bash
ok

Use this for Kubernetes liveness/readiness probes. It's lightweight and fast.

#Kubernetes Configuration

yaml
 1apiVersion: v1 2kind: Pod 3spec: 4  containers: 5    - name: app 6      livenessProbe: 7        httpGet: 8          path: /healthz 9          port: 300010        initialDelaySeconds: 511        periodSeconds: 1012      readinessProbe:13        httpGet:14          path: /healthz15          port: 300016        initialDelaySeconds: 517        periodSeconds: 5

#Docker Healthcheck

dockerfile
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3   CMD curl -f http://localhost:3000/healthz || exit 1

#Load Balancer Configuration

Most load balancers (AWS ALB, nginx, HAProxy) can use /healthz to check if instances are healthy:

AWS ALB:

bash
Health check path: /healthz
Healthy threshold: 2
Unhealthy threshold: 3
Timeout: 5 seconds
Interval: 30 seconds

nginx:

nginx
upstream backend {
  server app1:3000;
  server app2:3000;
  health_check uri=/healthz interval=10s;
}

#Custom Health Checks

Need to check database connectivity or external services? Extend the health check:

typescript
 1import { $action } from "alepha/server"; 2import { $inject } from "alepha"; 3import { DatabaseService } from "./DatabaseService"; 4  5class CustomHealthApi { 6  db = $inject(DatabaseService); 7  8  health = $action({ 9    method: "GET",10    path: "/health",11    handler: async () => {12      const dbHealthy = await this.db.ping();13 14      return {15        status: dbHealthy ? "ok" : "degraded",16        uptime: process.uptime(),17        checks: {18          database: dbHealthy ? "ok" : "error",19        },20      };21    },22  });23}

#Best Practices

  1. Keep /healthz fast - Don't do database queries or external calls
  2. Use /health for deep checks - Include dependency status
  3. Return appropriate status codes - 200 for healthy, 503 for unhealthy
  4. Don't expose sensitive info - Health endpoints are often public
  5. Set reasonable timeouts - Health checks should respond quickly
On This Page
No headings found...
ready
mainTypeScript
UTF-8guides_observability_health.md