Add a /health Readiness Check
Tell orchestrators when your service is ready to serve.
Add a /health Readiness Check is a free MLOps Academy lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the MLOps Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
How Does the Cluster Know?
Orchestrators like Kubernetes need a way to ask your service: are you alive, and are you ready to take traffic? A health endpoint answers that. 🩺
Liveness vs Readiness
Liveness asks if the process is running. Readiness asks if it can actually serve requests yet. They are two different questions.
A Trivial Health Route
The simplest check is a GET /health that returns ok. If the process can reply at all, it is at least alive.
@app.get("/health")
def health():
return {"status": "ok"}Readiness Needs the Model
For ML, alive is not enough. A real readiness check confirms the model finished loading before you accept prediction traffic.
Check the Loaded Model
You inspect app.state to see if the model is present. If it is still None, the service is not ready yet.
ready = app.state.model is not NoneSignal Not-Ready with 503
When the model is not loaded, return a 503 status so the orchestrator holds traffic back until you are ready.
from fastapi import HTTPException
raise HTTPException(status_code=503)Put It Together
A /ready route checks the model and returns ready or raises 503. The check stays fast and free of heavy work.
@app.get("/ready")
def ready(req: Request):
if req.app.state.model is None:
raise HTTPException(503)
return {"ready": True}Wire Up the Probes
In Kubernetes you point a readinessProbe at /ready and a livenessProbe at /health. The platform polls them on a schedule.
Keep Checks Lightweight
Probes run often, so a health check must be cheap. Never run a real model inference or hit a slow database inside it.
Smooth Zero-Downtime Deploys
Readiness checks enable rolling updates: new pods only get traffic once ready, so users never hit a half-started instance. 🚦
Why It Matters
Health and readiness endpoints make your model service a good citizen in any cluster, enabling safe scaling, restarts, and deploys. ✅
Quick Check
Your model is still loading and a readiness probe hits /ready. What should the endpoint return?
Recap
You split liveness from readiness, returned 503 until the model loads, and wired probes for safe deploys. Your service is cluster-ready! 🙌
Frequently asked questions
Is the “Add a /health Readiness Check” lesson free?
Yes — the full text of “Add a /health Readiness Check” is free to read here on the web, and the MLOps Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the MLOps Academy course, upgrade to CoddyKit PRO.
What will I learn in “Add a /health Readiness Check”?
Tell orchestrators when your service is ready to serve. You practise MLOps Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start MLOps Academy?
No prior experience is required. MLOps Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Add a /health Readiness Check” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this MLOps Academy lesson?
Yes. Every MLOps Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Your First /predict Endpoint
- Validate Requests with Pydantic
- Load the Model Once at Startup
- Add a /health Readiness Check