Health Checks
Liveness/readiness probes for API, workers, and GPU servers.
In plain words
Health checks are quick questions that ask each copy of your app if it's alive and ready for work, so traffic only goes to the ones that can handle it.
Think of it like…
A restaurant's pass: the kitchen signals when a dish is ready (readiness), a manager notices if a cook has collapsed and replaces them (liveness) and new cooks get time to set up their station before being judged (startup).
Where you’ve seen it
A self-hosted LLM server takes about 90 seconds to load weights. Its startup probe checks /healthz every 10 seconds and tolerates 30 failures (30 × 10 s = 300 s of grace), during which liveness and readiness probes are disabled. After startup, readiness hits /readyz every 5 seconds with a timeout of 2 seconds and failureThreshold: 2: it returns 200 only when the model is loaded, a 1-token warm-up generation succeeded and the request queue is below a limit, so overloaded pods stop receiving new traffic until they drain. Liveness checks an internal engine heartbeat every 10 seconds with failureThreshold: 3 (restart after 30 seconds of a stuck engine) and a longer timeout so a slow but working response doesn't trigger a restart. A GPU error (for example an unrecoverable CUDA error) makes liveness fail, restarting the pod and cordoning the node. The LLM gateway's readiness checks its own initialisation, Redis connectivity (cached for 10 seconds) and config load, but it does not call the model provider: if the provider has an outage, the gateway stays ready and serves fallbacks or clear errors, whereas probing the provider would mark all replicas unready simultaneously. On SIGTERM the pod fails readiness first, finishes in-flight streams within a 120-second termination grace period and exits.
Words you’ll hear
- Liveness probe
- Detects a hung process; failure causes a restart.
- Readiness probe
- Decides whether the instance should receive traffic.
- Startup probe
- Gives slow-starting containers time before other probes begin.
- Warm-up request
- A real small inference run proving the model can generate.
Visual diagram
Theory & deep dive
What each probe should check
Liveness answers "is the process stuck beyond recovery?" Keep it cheap and local: the event loop responds, the engine's heartbeat advanced recently, no unrecoverable GPU error. Don't include external dependencies (a database blip shouldn't restart every pod) and use a generous timeout and a failure threshold (3 failures at 10 s intervals means 30 s before restart) so garbage collection pauses and GPU initialisation don't cause restarts. Readiness answers "should this instance receive traffic now?": configuration loaded, model loaded and warmed up, local dependencies reachable (cached checks), queue depth under a threshold. A pod that fails readiness is removed from the Service endpoints but not restarted, which is the right response to temporary overload or a downstream blip. Startup probes protect slow starters: for a model that loads in about 90 seconds, allow 300 seconds (30 failures at 10-second intervals) so liveness doesn't kill it mid-load.
Implementation details: serve /healthz and /readyz on a separate lightweight handler (or port) so they respond even when the main request path is saturated; return structured status with per-check results for humans and a simple HTTP 200/503 for machines; cache dependency checks for 10 to 30 seconds so probes (every 5 to 10 seconds across many replicas) don't hammer databases or Redis; and keep probes idempotent and cheap. For GPU servers, a warm-up generation (one token from a real prompt) proves the engine, CUDA context and weights work; include GPU health (memory errors, driver state) in liveness and trigger node cordon and replacement on persistent faults.
startupProbe: path /healthz, periodSeconds 10, failureThreshold 30 (300 s). readinessProbe: path /readyz, periodSeconds 5, timeoutSeconds 2, failureThreshold 2. livenessProbe: path /healthz, periodSeconds 10, timeoutSeconds 5, failureThreshold 3.
Dependencies, provider outages and graceful shutdown
Decide carefully which dependencies gate readiness. Local, required resources (config, model weights, a database the service can't work without) can; shared third-party dependencies (the LLM provider, a SaaS API) generally should not, because when they fail, every replica fails readiness at once, the load balancer has no healthy backends and the service returns errors to everyone, including requests that could have been served from cache, a fallback model or a graceful message. Instead, report dependency state in a separate, non-gating status endpoint and metrics, use circuit breakers and fallbacks (see model fallbacks) and surface degraded mode to users. Likewise don't make probes call the provider on every check: at 3 replicas × one probe every 10 seconds that is 25,920 calls a day of pure waste and rate-limit consumption.
Graceful shutdown: on SIGTERM, immediately start failing readiness so the load balancer stops sending new requests, finish in-flight work (for streaming LLM responses this can take minutes: set the pod's terminationGracePeriodSeconds to about 120 s) and exit; use a preStop hook with a short sleep to cover endpoint-propagation delay. Rolling updates depend on correct readiness: new pods must pass readiness before old pods are removed (see Kubernetes lesson). Test probes with failure drills (kill the model process, fill the queue, make Redis unreachable, simulate a GPU fault) and watch what the platform does, and monitor restart counts, readiness flaps and time to ready as signals of badly tuned checks.
Provider outage for 10 minutes. With provider-gated readiness: all 3 replicas go unready, the balancer returns 503 to everyone. With non-gating readiness: replicas stay in service, cached answers and the fallback model keep serving, and the dashboard shows "provider degraded".
How it works, step by step
Step 1 of 41. Define endpoints and semantics
Create /healthz (local liveness) and /readyz (ability to serve) on a lightweight handler with structured output.
- Cache
- dependency checks 10–30 s
When to use it & trade-offs
What it is
Health checks let platforms and load balancers decide whether to route traffic to, restart or wait for an instance. Kubernetes defines three probes: startup (has the process finished booting, which matters for slow model loads), readiness (can this instance serve requests right now? if not, remove it from the Service) and liveness (is the process stuck? if so, restart it). Typical endpoints are /healthz (liveness: the process responds) and /readyz (readiness: dependencies and model are ready). For AI services, a GPU model server is ready only after weights are loaded and a warm-up generation has succeeded, and third-party provider health should generally *not* make readiness fail, because it would remove every replica at once.
Why it matters: Bad health checks cause outages. Too shallow and traffic hits instances that can't serve (a model still loading, a GPU in an error state). Too deep and a flaky dependency marks every replica unready, so the whole service disappears. Liveness probes that are too aggressive restart healthy pods during long garbage collections or GPU initialisation, creating restart loops. AI workloads add slow starts, expensive dependency calls and GPU-specific failures, so probes need deliberate design.
When to reach for it
- Kubernetes deployments of gateways and model servers
- Load balancer target health
- Safe rolling updates and graceful shutdown
When to avoid or be careful
- Making readiness depend on the LLM provider's health
- Liveness probes that check external dependencies
- Probes that run expensive inference on every call
Probe types
Strengths: Automatic restarts.
Watch out: Too aggressive settings cause restart loops.
Strengths: Protects users during overload and warm-up.
Watch out: Over-deep checks can remove all instances.
Strengths: Prevents premature kills.
Watch out: Delays failure detection during boot.
Interview signals & numbers to know
When this topic comes up
- “Pods keep restarting while loading the model”
- Readiness vs liveness
- Startup probe
- Warm-up request
- Graceful shutdown
Benchmarks & rules of thumb
- 30 × 10 s = 300 s
- startup grace for a 90 s model load
- 25,920
- daily provider calls if 3 replicas probe it every 10 s
- 120 s
- example termination grace period for streams
Common mistakes & follow-ups
Common interview mistakes
- Using one endpoint for liveness and readiness.
- Restarting pods because a shared database was briefly slow.
- Ignoring that readiness must fail first on shutdown.
Likely interviewer follow-ups
- What is the difference between liveness and readiness?
- How would you configure probes for a slow-loading model server?
- Why shouldn't readiness check the LLM provider?
Knowledge check
Put it into practice
Practice related interview Q&A
Apply Health Checks with generative AI interview Q&A and hands-on practice.