Interview's MateAI Engineering
Interview's Mate

AI Engineering

LLMs, RAG, agents & evals

Visualizer

DSA Visualizer
All 32 lessons
Custom Playground
Try your own examples

Learning

System Design
31 architecture topics
SQL Learning
160 foundations → production topics
AI Engineering
160 LLM → backend topics
Data Science
160 Python → MLOps topics
Data Engineer
160 SQL → streaming topics
Docker
160 Docker learning topics
Kubernetes
160 K8s fundamentals → cloud
Java LearnSoon
Coming soon
Python Learn
Interview Q&A & internals
JavaScript Learn
Closures, async & DOM Q&A
Tech Learn
Search, practise & track Q&A
AI DSA Practice
Solve coding problems
Theme
Home
AI Engineering topics
Lesson 138/ 160
07. Deployment

Health Checks

Liveness/readiness probes for API, workers, and GPU servers.

BeginnerLiveness · Readiness3 quiz questions
Practice Generative AI Q&A
In plain wordsDiagramTheoryStep by stepWhen to use itInterview cluesMistakes to avoidHands-onQuiz (3)Practice

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

Loading interactive 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.

Probe settings

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.

Key takeaway: Keep liveness local and lenient, make readiness reflect ability to serve, and give slow starters a startup budget.

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.

Why not probe the provider

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".

Key takeaway: Don't gate readiness on shared third-party services, cache dependency checks and drain gracefully on shutdown.

How it works, step by step

Step 1 of 4
Engineering

1. Define endpoints and semantics

Create /healthz (local liveness) and /readyz (ability to serve) on a lightweight handler with structured output.

200/503 + per-check detail
Key numbers at this step
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

Liveness
Best for: Recovering from stuck processes

Strengths: Automatic restarts.

Watch out: Too aggressive settings cause restart loops.

Readiness
Best for: Routing traffic only to instances that can serve

Strengths: Protects users during overload and warm-up.

Watch out: Over-deep checks can remove all instances.

Startup
Best for: Slow model loads

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?
Interview tip: Explain why provider health shouldn't gate readiness. It shows you understand correlated failures across replicas.
Loading hands-on exercise

Knowledge check

Loading quiz

Put it into practice

Practice related interview Q&A

Apply Health Checks with generative AI interview Q&A and hands-on practice.

Open Generative AI Q&A →Tech Learn Q&A
Previous topic
Model Versioning
Next topic
Alerts and Dashboards