Lesson deck

ML system design: framing, budgets, two-stage retrieval, serving, rollout and monitoring flashcards

Reviewing needs JavaScript. You can read every card in the list below.

Loading your cards...

Back to the lesson18 cards in this deck

Read all 18 cards as a list
  1. Front
    When should you not start with ML, and what do you ship instead?
    Back
    When rules already solve the problem acceptably, there is no label or feedback signal, an error is too costly without human review, or explainability rules out opaque models. Ship a heuristic baseline first, log its decisions and corrections as labels, and build a model only if the remaining errors justify the cost.
  2. Front
    Business goal, training objective and metric. How do they differ, and what is a guardrail?
    Back
    The goal is why the system exists (more orders). The objective is what the model optimises (probability of an order). Metrics decide whether it worked (NDCG@k offline, order rate online). A guardrail is a metric you will not let get worse, such as delivery ETA or cancellations. A proxy objective such as clicks can rise while the goal falls.
  3. Front
    List the nine steps of the ML system design framework.
    Back
    1 Clarify and frame. 2 Data and labels. 3 Baseline. 4 Features. 5 Model. 6 Offline evaluation. 7 Serving. 8 Online evaluation and rollout. 9 Monitoring and risks. A suggested 35-minute split is 4, 4, 2, 4, 5, 3, 5, 3, 5 minutes. Say the trade-off, start with a baseline, name the failure mode first.
  4. Front
    Batch, online and streaming inference. When does each fit?
    Back
    Batch: scores computed on a schedule, good when freshness tolerates it, stale between runs. Online: computed per request, needs a tight latency budget. Streaming: features updated as events arrive, most moving parts. Real systems mix them, using the slowest mode each feature's freshness allows.
  5. Front
    State Little's law and use it to size a service.
    Back
    In flight L = arrival rate x time in system. Feed example: 694.44 requests per second x 0.060 s = 41.7 in flight. With 8 concurrent per server loaded to 50%, each carries 4, so 11 servers; at $0.40 per server-hour that is $5.28 per million requests. Every assumption (peak factor, service time, utilisation) is a lever to state.
  6. Front
    Why budget p99 latency instead of the mean, and how do parallel calls combine?
    Back
    In the script the mean was 45.2 ms but p99 was 126.2 ms and the slowest request 277.5 ms. Serial steps add; parallel calls cost the slowest one (5 + [10, 40] = 45 ms, not 55). With 10 parallel calls each slow 1% of the time, 1 - 0.99^10 = 0.0956 of requests wait on a slow one.
  7. Front
    What is a timeout with a fallback, and what does it cost?
    Back
    Stop waiting at a threshold and return a cheaper answer. A 100 ms timeout with a 5 ms fallback sent 3.20% of requests to the fallback and capped the slowest served request at 105.0 ms instead of 277.5 ms. The price is quality on those requests, so the fallback rate is a metric to alert on.
  8. Front
    Why use a retrieve-then-rank funnel, and what does each stage optimise?
    Back
    Scoring every item with the best model is too slow or costly. Candidate generation (two-tower plus ANN, popular, recent) keeps a few hundred and is judged by recall. The ranker orders them with rich features and is judged by NDCG or precision at the top. The re-ranker applies diversity, rules, fairness and exploration.
  9. Front
    Why does final quality depend on retrieval recall? Give the numbers.
    Back
    The ranker cannot promote an item it never sees. In the synthetic funnel, final NDCG@10 was 0.472 with 50 candidates (recall 0.165), 0.772 with 500 and 0.903 with 2,000, against 0.944 when the ranker scored all 20,000 items. More candidates raise quality and ranker cost together.
  10. Front
    Define recall@k and NDCG@k.
    Back
    Recall@k = relevant items in the top k divided by all relevant items. NDCG@k = DCG@k / ideal DCG@k, where DCG sums gain / log2(rank + 1). A perfect list scores 1. By hand, gains 1 and 3 in the order (1, 3) give 2.893 / 3.631 = 0.797.
  11. Front
    What are the special problems of fraud and ads designs?
    Back
    Fraud: extreme imbalance, delayed and selective labels (keep a random approval holdout), adaptive adversaries, a decision from costs: act when p > F / (F + L), for example 4 / 84 = 0.0476, which needs calibrated scores. Ads: value is pCTR x bid, so calibration matters; an overstated pCTR (0.04 instead of 0.02) doubles the value from $0.03 to $0.06.
  12. Front
    How do you keep training and serving features consistent?
    Back
    Use one feature definition for both paths, re-use code, log the features actually served, and train on the logs. A feature store (offline side with point-in-time joins, online side for low latency) gives the definition a home; it adds a system to run, so it pays off when many models share features.
  13. Front
    Name the four serving levers and the cost of each.
    Back
    Cache: stale answers and a hit rate that depends on skew (0.391 at 1% of keys in the script). Batching: throughput up, latency up (batch 16 gives 1000 items/s at 16 ms). Quantisation: 400 MB to 100 MB for 100M parameters, some accuracy lost. Distillation: train a smaller student from a larger teacher, pay for training twice.
  14. Front
    Describe the rollout ladder.
    Back
    Offline evaluation, then shadow (score and log, users see nothing), canary (small share of real traffic), A/B test (randomised, primary metric with guardrails), ramp to 100%, with rollback ready at each stage. Each step answers a different question: does it run, does it break anything, is it better, does it hold at scale.
  15. Front
    What is a feedback loop in an ML system, and how do you limit it?
    Back
    The model's output changes what users see, which changes its next training data. In the toy loop, always showing the best observed item gave one item 0.998 of impressions and found the truly best item in 14 of 100 runs. Exploring 10% of the time found it in 55 of 100. Keep an exploration or random holdout slice and log propensities.
  16. Front
    What should you monitor after launch beyond accuracy?
    Back
    Data quality, feature drift, score drift, and performance once labels mature, plus latency percentiles, error and timeout rates and the fallback rate. A fallback rate that rises unnoticed means users quietly get a worse answer while accuracy on the requests the model did answer looks fine.
  17. Front
    Name the ML-specific risk factors from the technical debt paper and a defence for one.
    Back
    From its abstract: boundary erosion, entanglement, hidden feedback loops, undeclared consumers, data dependencies, configuration issues, changes in the external world, system-level anti-patterns. Defence example: for undeclared consumers, version your outputs and keep a registry of who reads them. Every part needs an owner, a test and a monitor.
  18. Front
    What belongs in a fallback and human-review design?
    Back
    A fallback ladder (full model, cheaper model, cached or popular default, rule) decided in advance, timeouts shorter than each call's budget share, an explicit fail-open or fail-closed choice for safety checks, and human review for the uncertain middle band and costly errors. Reviewer capacity and alert fatigue limit how wide that band can be.