SwaggerPulse journal
Health Check API Best Practices for Monitoring That Works
Key takeaways
- Split health endpoints into three: liveness for the orchestrator, readiness for the load balancer, and a deep dependency check for monitoring tools.
- Never wire deep dependency checks into liveness probes, because a slow database will restart healthy containers and cause crash loops.
- Keep health endpoints public or token-gated, with explicit timeouts on every outbound call and no secrets in the response body.
- Point Prometheus at per-dependency gauges with a for: clause, and point external uptime monitors at a publicly reachable deep endpoint.
- Cache dependency results so a deep check runs at most once per minute, preventing one outage from multiplying into hundreds of checks.
Health check API best practices boil down to one rule: split your health endpoint into three, and route each to the right consumer. Liveness answers "is the process running?" for your orchestrator, readiness answers "can this instance take traffic?" for your load balancer, and a deep check that probes dependencies belongs behind Prometheus or an external uptime monitor, never behind a probe that restarts containers.
What is the difference between liveness, readiness, and deep health checks?
Three distinct questions, three distinct endpoints. Liveness asks: is the process alive? Readiness asks: can it serve traffic right now? Deep checks ask: are the dependencies healthy? Mixing them into one endpoint is the fastest route to false alerts.
Liveness: is the process alive
A liveness check should touch nothing but the process itself. No database ping, no cache lookup. If the process can execute a handler and return 200, it is alive. Restarting a container because Postgres is slow turns a dependency problem into a crash loop.
Readiness: can it serve traffic
Readiness adds the minimum a request needs to succeed: a connection pool that accepts connections, config loaded, migrations applied. It gates load balancer and Kubernetes traffic, so keep it cheap and fast. Kubernetes documents this split between liveness, readiness, and startup probes in its own probe documentation.
Deep checks: are dependencies healthy
Deep checks verify each dependency individually: database round-trip, queue reachability, downstream API auth. They are diagnostic, not traffic-gating. Point your monitoring at them, not your load balancer. SwaggerPulse consumes these endpoint checks directly from your OpenAPI spec, so each path gets its own uptime check.
Which monitoring system should consume which health endpoint?
Match each endpoint type to the consumer that can actually act on it. Orchestrators and load balancers need fast, cheap binary answers. Metrics systems need richer data on a schedule. External uptime monitors need an internet-reachable URL that approximates what a real client experiences.
Orchestrators and load balancers
Feed these your liveness and readiness endpoints only. Kubernetes restarts pods on liveness failure and pulls them from Service routing on readiness failure, so a slow dependency check here causes restart storms, not insight. AWS ELB target group probes belong in the same bucket: keep them shallow, fast, and dependency-free. Never point a load balancer at your deep check.
Prometheus and metrics-based monitoring
Prometheus should scrape a dedicated /metrics endpoint, not your health endpoints. If you want dependency health as time series, expose gauges like dependency_up per dependency and let Prometheus record them. Alert rules then live in Prometheus, where you can add for: clauses to stop flapping.
External uptime monitors
Point external monitors at a deep or aggregated endpoint that is publicly reachable. This is the consumer that catches DNS, CDN, and TLS failures your in-cluster checks never see.
| Consumer | Endpoint | Check depth | Failure action |
|---|---|---|---|
| K8s / ELB | /healthz, /readyz | Shallow | Restart / route removal |
| Prometheus | /metrics gauges | Per-dependency | Alert after for: window |
| External monitor | /health/deep | Full dependencies | Email / status page |
One caveat for SwaggerPulse: it consumes whatever endpoint you register against your OpenAPI spec, so it sits in the external-monitor row. It cannot see in-cluster-only failures, so pair it with Prometheus rather than replacing it.
What should a health check API response body contain?
The body should answer one question per endpoint. A liveness check can return a bare {"status":"ok"} with a 200. A readiness check should name what it verified, so a 503 tells you which dependency failed without SSHing into the box.
Status codes that mean something
Return 200 only when the checks that endpoint owns pass, 503 when they fail, and 504 when a dependency times out. Load balancers only read the status code: AWS target group probes count a target healthy on any 2xx or 3xx response and ignore the body entirely (AWS docs). So put detail in the body for humans and dashboards, and keep the status code unambiguous for machines.
What to expose and what to hide
Include uptime, version, and response times per dependency. Hide connection strings, hostnames, and stack traces: health endpoints are public by default. If your spec drives your monitoring, document each check in the paths object so spec consumers see what a 503 means per route.
How do you configure Prometheus to scrape an API health endpoint?
Point a scrape_config at your health endpoint the same way you would any metrics path. A minimal entry in prometheus.yml:
scrape_configs:
- job_name: 'api-health'
metrics_path: '/health'
scheme: https
static_configs:
- targets: ['api.example.com:443']
Prometheus only needs the endpoint to return a 2xx; the response body is ignored unless you expose metrics on it.
Scrape intervals and timeouts
Set scrape_interval: 30s and scrape_timeout: 10s for a health job. A shorter interval burns request budget on your dependency checks; a longer one delays detection. If your deep check hits a slow third-party dependency, keep the timeout under the interval so a hung check never overlaps the next scrape. Match these to the interval your dependency checks actually run at, not faster.
Turning health checks into alert rules
Prometheus's up metric is per-target, so a failed scrape fires on the whole job, not one endpoint. For per-endpoint readiness, have your API export a metric like api_dependency_up{dependency="db"} 0 and alert on it:
- alert: DependencyDown
expr: api_dependency_up == 0
for: 2m
The for: 2m clause filters single-scrape blips. If you would rather not run a Prometheus server at all, SwaggerPulse drives endpoint checks from your OpenAPI spec and emails on downtime, and UptimeRobot or Checkly cover similar ground.
How do AWS load balancer health checks differ from application health checks?
An AWS load balancer probe answers one question: should this target receive traffic? It is not a monitoring system, and treating it like one is how false alerts start.
Target group probe settings
A target group health check takes an HTTP path, a success code (default 200), an interval, a timeout, and healthy/unhealthy thresholds. With defaults of 30 seconds and 2 failures, a target is pulled after roughly a minute. The probe result never leaves the load balancer: no history, no response-time tracking, no downtime email alerts. Your ELB settings decide routing, not paging, so they should stay coarse and sit alongside a real monitor rather than replace one.
Why the ELB probe should hit a cheap endpoint
Point the probe at a lightweight liveness path, not a deep dependency check. A probe that queries the database on every interval can flap targets in and out of rotation during a slow query, and the load balancer gives you no spec change history or response body to diagnose why. Keep the probe dumb, keep your OpenAPI-documented deep checks behind a separate path, and let your monitoring tool consume that instead. Prometheus, for example, scrapes on its own configured intervals independent of your load balancer (Prometheus configuration docs).
How do you aggregate multiple API health checks into one dashboard?
Self-hosted vs hosted trade-offs
Self-hosted wins on cost and control. Uptime Kuma, the tool readers in this space name most often, runs on a single box and checks whatever URLs you point it at. The trade-off is that you own the infrastructure: the server it runs on becomes another thing that can fall over, and you have to keep it patched. Hosted tools like UptimeRobot or Checkly remove that burden but charge per monitor, which gets expensive fast if your OpenAPI spec describes dozens of endpoints. The middle path is to aggregate at the spec level. Your Swagger JSON already lists every path you care about, so a dashboard driven by the spec turns one maintenance task (keeping the spec current) into full endpoint coverage, instead of asking you to hand-register each route in a separate monitoring tool.
Running the same criteria over SwaggerPulse
SwaggerPulse takes that middle path: sign in with GitHub, paste your Swagger JSON URL, and it generates endpoint checks from the paths object, with downtime email alerts and a public status page. The Free tier covers 10 monitors and 100 endpoints, and Pro is £7.99. It is hosted, so you carry no infrastructure, but that also means you cannot customise the checks the way you could with Uptime Kuma running on your own box. If you want PagerDuty-style integrations or deep status page CSS control, it will not do that today. Where it fits is if your spec is already the source of truth and you want uptime checks to follow it automatically rather than maintaining a parallel monitor list.
How often should a health check endpoint run dependency checks?
Run liveness checks every 10-30 seconds, but cache dependency results so the deep check itself hits Postgres, Redis, or downstream APIs no more than once per minute. A scraper polling every 15 seconds should read a cached result, not re-run the query. This keeps a dependency outage from multiplying one failure into hundreds of checks, which is what trips rate limits and turns a slow database into a self-inflicted DDoS.
If you do want to alert on the dependency check itself, Prometheus alerting rules let you set a for: duration so a single bad scrape doesn't page you: Prometheus alerting rules documentation. The same logic applies to hosted uptime checks: a 30-60 second interval on a deep endpoint is plenty, and SwaggerPulse follows the same pattern, polling the spec-driven endpoint without re-executing dependencies on every run.
What are common health check API mistakes that cause false alerts?
Three mistakes cause most false alerts: auth on health endpoints, deep checks wired into liveness, and missing timeouts.
Putting auth on a health endpoint means your monitor gets a 401 and reports downtime while the API is fine. Health endpoints should be public or token-gated with a token your monitor actually holds, and they should never sit behind session middleware.
Deep dependency checks belong on the readiness endpoint, not liveness. If a database blips for two seconds and liveness fails, your orchestrator restarts a perfectly healthy pod, or your uptime monitor pages you for nothing. Liveness should answer "is this process alive" in milliseconds; readiness can afford a couple of hundred.
Missing timeouts are the sneaky one. A dependency check with no timeout hangs, the check never returns, and the monitor times out on its side, marking you down. Set explicit timeouts on every outbound call inside a health check, and cap the whole endpoint at a few seconds.
Run your own checks against the same rules: if a spec-driven monitor like SwaggerPulse hits your readiness endpoint every minute and a slow dependency occasionally breaches the timeout, that is a monitoring design problem, not an outage. Fix the check, not the alert threshold.
FAQ
Should a health check endpoint require authentication?
No. Auth on a health endpoint means your monitor gets a 401 and reports downtime while the API is fine. Keep liveness and readiness public, or gate them with a static token your monitoring tool actually holds. They should never sit behind session middleware, and they must not leak connection strings, hostnames, or stack traces in the response body.
What port and path should I use for a health check API?
There is no required port: the endpoint lives on the same port your API serves traffic on. For paths, the convention is /healthz for liveness, /readyz for readiness, and something like /health/deep for the dependency check. Document each path in your OpenAPI spec so spec-driven monitors and teammates know what a 503 means per route.
Can I reuse my Kubernetes readiness probe as a public status page check?
Not directly. Your readiness endpoint is usually in-cluster only, so an external monitor cannot reach it, and it cannot see DNS, CDN, or TLS failures anyway. Expose a publicly reachable deep or aggregated endpoint for the status page instead. Pair the two: the external check catches edge failures, Prometheus covers in-cluster dependency health.
Do I need a separate health endpoint if I already have Prometheus metrics?
Yes, because they answer different questions. Prometheus scrapes /metrics for time series and alerting, while liveness and readiness endpoints give orchestrators and load balancers fast binary answers for routing and restarts. A metrics endpoint cannot gate traffic. Keep all three, and expose per-dependency gauges like dependency_up so alert rules can fire per endpoint.