AI / ML Engineer · Focus area 2: MLOps
ML8: Serving models
Goal: put a trained model behind a dependable API: choose batch or online predictions, validate every input, keep training and serving consistent, meet a speed target, and package the model with its versions.
You'll need: ML1 to ML7, Module 25 (APIs and JSON), Module 47 (REST API Design), Module 69 (Docker), Python 3.11 or newer with FastAPI (tested with 0.162.0), and the DakDost practice kit.
Where this is used: a model only helps when other software can use it: a booking screen asking "is this parcel likely to be late?", a nightly job scoring all of tomorrow's parcels, an app showing a delivery estimate. Serving is where data science meets backend engineering.
How it differs: the Backend path builds APIs whose rules are written by people. A model API has extra failure modes: inputs the model has never seen, features computed differently from training, answers that are probabilities, and a model file that has its own version.
Time: reading about 2 hours · practice (the Try it tasks) about 3 hours · assignment about 3 hours.
Lessons
- 1Batch or online predictionsReading 15–25 minutes, plus practice✓
- 2An API with validation, using FastAPIReading 15–25 minutes, plus practice✓
- 3Training/serving skew and versionsReading 15–25 minutes, plus practice✓
- 4Speed, batching and limitsReading 15–25 minutes, plus practice✓
- 5Packaging and deploying a model serviceReading 15–25 minutes, plus practice✓
🛠️Assignment: DakDost's late-parcel API
This is the main part of Project 2.
- Write a pydantic
Shipmentmodel with types, allowed categories, ranges andextra='forbid', and use it for/predict. - Return probability, decision, threshold, model version and a request id; log the same without any personal data.
- Use the shared
build_frameand saved pipeline, and add a test that compares the API with the offline model at four booking times. - Add
/predict/batchwith a limit of 100 and a clear413above it. - Measure p50 and p95 for 200 single calls and one batch of 100, and record where you measured.
Self-check before you finish:
- [ ] A request with a phone number is rejected.
- [ ] The API and the offline model agree at 00:30 and 23:50 India time.
- [ ] Every response and log line has the model version.
- [ ] Your latency figures say what hardware they come from.
- [ ]
pytest tests/test_serve.pytests 1 to 6, 8 and 10 pass.
✅Module check
Explain in a few sentences, in your own words:
How do you serve a model so that its answers can be trusted in use?
Show a good answer
A good answer mentions: choosing batch or online from when inputs are known and answers are needed, with a fallback; a schema that rejects missing, unknown, impossible and extra inputs with clear errors; responses with probability, decision, threshold, version and a request id; one shared feature function and a saved pipeline to avoid training/serving skew, checked by comparing the API with the offline model; pinned library versions; latency reported as percentiles, batching for many rows and size limits; and packaging with versioned model files chosen by a setting, health checks, and shadow or canary releases with a way back.
📚Official references
Official documentation and guidance for this module's topics, chosen on 2 November 2026. Tools, laws and standards change, so check the current version before you rely on a detail. If a link has moved, search the same site.
📝Module quiz
10 questions · 10 marks each · 100 marks in all · pass mark 70% · retry as often as you like ·
