FastAPI Model Serving, Pydantic Schema Validation & Latency Simulator
Send good and bad patient payloads to /predict and see Pydantic reject them at the door. Then load the service and watch latency explode as workers saturate — queueing theory, not magic.
Predict first
Commit to a guess before you touch anything. Being wrong here is how it sticks.
An endpoint handles 120 req/s with 25 ms average latency. How many requests are in flight on average?
Experiment
Move the controls and watch the outputs. Goals tick off automatically when you reach them.
Pydantic at the boundary
{"stroke_probability": 0.384, "risk_tier": "HIGH", "action": "Refer to chronic care clinic"}Throughput, latency & Little's Law
Latency ≈ service time / (1 − ρ): it stays flat until ρ ≈ 70%, then shoots up.
Explain it
Put what you saw into words. This is what the exam will ask you to do.
How does Pydantic protect the model code, and how would you scale CPU-bound inference in FastAPI?
Code it
Write real code against real data. Python and SQL run right here in your browser and hidden tests check your work; the AI reviews it like an examiner.
The Patient request schema
Define Pydantic models for the stroke API:
Patient:agefloat 0–120;avg_glucose_levelfloat > 0;bmioptional float between 10 and 80 (defaultNone);hypertensionandheart_diseasebools;smoking_statusone of"never","formerly","smokes","unknown".Prediction:stroke_probabilityfloat 0–1,risk_tierone of"LOW","HIGH",model_versionstr.
Challenge
Fixed variations, a new problem every day, and unlimited AI challenges built from your current settings.
Little's Law API Concurrency Capacity
A stroke screening endpoint handles an arrival rate λ = 250 requests/sec with average model inference latency W = 40 ms (0.040s). According to Little's Law (L = λ × W), how many concurrent requests are in flight on the server?