AI Engineer Portal
Your personal operating system for career transition.
Exercise
Add health and readiness probes to an LLM service
Add Health and Readiness Probes to an LLM Service
Kubernetes and cloud load balancers use two distinct probes to manage container lifecycle:
- Liveness probe (
/health/live): is the container alive? If it fails, kill and restart it. - Readiness probe (
/health/ready): is the container ready to serve traffic? If it fails, stop routing requests to it — but do not kill it.
These semantics matter for LLM services. A container can be alive (process running) but not ready (model still loading, provider API unreachable, or token budget exhausted for the day). Conflating liveness and readiness causes cascading restarts and dropped traffic.
What to build
Implement a HealthChecker class that powers both endpoints:
is_alive() -> LivenessResult— checks that the process is running and has not entered a fatal error state. Should almost always return healthy; only fail on unrecoverable conditions.is_ready() -> ReadinessResult— checks that all dependencies needed to serve requests are available: provider reachability, model loaded, config valid, queue not saturated.- Both methods return a typed result with
healthy: bool,checks: dict[str, CheckResult], andlatency_ms: int. - Each individual check in
is_ready()should time out independently (default 2 seconds) so one slow dependency does not block the whole probe. - The readiness result should report
degraded: bool— True when some non-critical checks fail but the service can still partially serve requests.
Constraints
- Use only the Python standard library and dataclasses.
- Each dependency check is a callable
async () -> bool. - Readiness is healthy if all critical checks pass (even if non-critical checks fail).
- Implement a
check_provider_reachabilitystub that simulates an async HTTP ping.
Api Async / medium / Step 9 of 23
Async and provider control
Make waiting behavior explicit. Timeouts, retries, and concurrency limits matter more than squeezing everything into one helper.
- - Uses async boundaries coherently
- - Makes timeout and retry decisions legible
- - Would be maintainable under provider instability
- - Is timeout behavior explicit?
- - Is retryable failure separate from terminal failure?
- - Would logs reveal what actually timed out?
Practice
Generate a variation
Generate a new exercise variation to deepen understanding or practice a related concept.
Attempt history
Recent submissions
Before you submit, decide what a strong answer should make obvious to the reviewer.
No attempts yet.