ML System Design · Module 3 of 47 · 11 concepts · about 14 min

Framing the Problem

How to turn a vague business goal into a precise ML task: the questions to ask first, choosing exactly what to predict, the metrics that connect the model to the business, the constraints, and the simple baseline every model must beat.

At work: The first week of every ML project, and the first five minutes of every ML design interview. A wrong framing here wastes every later week.

Start from the business goal

What it is

Every ML project starts with a goal stated in business terms, not model terms:

  • 'Increase how much people buy per visit' (not 'build a recommender').
  • 'Stop losing money to fraud without annoying honest customers' (not 'train a fraud classifier').
  • 'Waste less fresh produce' (not 'forecast demand').

The model is one possible way to reach the goal. Write the goal down first, and come back to it at every decision.

Why it matters

The goal decides what 'good' means.

  • 'Increase basket size' and 'increase repeat visits' lead to different recommendation models.
  • The goal also tells you when to stop: a model that is more accurate but does not move the goal is not better.

In the real world: A grocery app asked for 'personalised recommendations' discovers the real goal is fewer forgotten items; a 'buy again' list of the customer's usual products delivers most of it with no model at all.

Accepting the solution as the problem. 'We need a deep learning recommender' is a solution; asking 'what should change for the business if it works?' often reveals a simpler way.

Clarifying questions to ask first

What it is

Before designing anything, ask about five things:

  • Goal: what business result should change, and how is it measured today?
  • Users and scale: who uses it, how many, how many requests a second at peak?
  • Time limit: does the prediction have to be ready in milliseconds, or can it be computed overnight?
  • Data: what is logged today? Are there right answers (labels), and how long until they arrive?
  • Constraints: privacy rules, explanations required, devices it must run on, budget.

Why it matters

Each answer removes options.

  • 'Overnight' allows batch prediction; '50 ms' rules out large models at request time.
  • 'Labels arrive after 60 days' means you cannot judge a new model quickly.
  • In an interview, these questions are scored: they show you know what matters before you know the answer.

In the real world: Interviewers at large tech companies say the strongest candidates spend three to five minutes on questions, write the answers on the board, and refer back to them for every later decision.

Visual example

Questions

If the answer would not change a decision, skip the question.

Questions that change the design, and how
ask aboutexample questionwhat the answer changes
GoalWhat metric should move?The label and the success measure
ScaleHow many requests a second at peak?Serving design and cost
Time limitHow fast must the answer be?Batch or live; model size
LabelsWhere do right answers come from, and when?Training data; how fast you can evaluate
ConstraintsMust it explain decisions? Run on a phone?Model family; where it runs

Asking twenty questions and designing nothing. Ask the five that change the design, state assumptions for the rest ('I'll assume ten million daily users'), and move on.

Choosing the prediction target

What it is

The prediction target is the exact thing the model outputs. It must be:

  • connected to the business goal;
  • observable: you can later see whether it came true, so you have labels;
  • available soon enough to train and evaluate on;
  • specific: a precise event in a precise window, such as 'the user adds this item to the basket within this session'.

Why it matters

A vague target gives a vague model.

  • 'Will the user like this product?' cannot be observed.
  • 'Will the user add it to the basket in this session?' can, within minutes, millions of times a day.
  • The choice of window matters too: 'buys within 7 days' and 'buys within the session' train different models.

In the real world: Kirana Kart's recommender predicts 'added to basket in this session' rather than 'clicked', because clicks on a grocery app often mean curiosity, while adding to the basket is close to buying.

Visual example

Target

The chosen target trades signal volume against closeness to the goal.

Candidate targets for Kirana Kart's recommendations
targetvolume of labelsclose to revenue?delay
Item viewedVery highWeakSeconds
Item clickedHighModerateSeconds
Added to basketMediumStrongMinutes
PurchasedLowerDirectMinutes to hours
Bought again within 30 daysLowVery strong (loyalty)30 days

Choosing a target that is easy to measure but rewards the wrong thing. Optimising for clicks alone teaches a recommender to show tempting but unwanted items, which raises clicks and lowers purchases.

One problem, several framings

What it is

The same goal can usually be framed as more than one ML task. For 'show each customer good products':

  • Classification: for each product, the probability this user adds it to the basket. Then sort.
  • Ranking: directly learn the order of products for this user.
  • Regression: predict how much the user would spend on each product.
  • Retrieval: find the products whose embedding is closest to the user's.

Large systems often combine framings: retrieval to find candidates, classification or ranking to order them.

Why it matters

The framing decides the labels, the model, the metrics and the cost.

  • Pointwise classification is simple and well understood.
  • Ranking matches what the user sees.
  • Retrieval scales to millions of items where scoring each one is impossible.
  • Naming the alternatives and choosing one with a reason is a strong interview move.

In the real world: YouTube's well-known recommendation paper framed candidate selection as classification over millions of videos, then ranking as predicting watch time, not clicks, to avoid rewarding clickbait.

Framing delivery time as classification ('late or on time?'). The product shows a number of minutes, so regression is the natural framing, and a yes/no throws away most of the information.

Business, product and model metrics

What it is

Three levels of metric connect a model to the business:

  • Business metric (the north star): revenue, orders, cost of fraud. What leadership cares about. Slow and noisy.
  • Product metric: basket additions per session, complaints about late delivery. Moves faster, measured in experiments.
  • Model metric: precision, recall, NDCG, error in minutes. Measured offline, in minutes, before launch.

Plus guardrail metrics: things that must not get worse, such as app speed, cancellations or complaints.

Why it matters

Each level answers a different question.

  • Model metrics let you iterate quickly offline.
  • Product metrics, from an A/B test, tell you whether users responded.
  • Business metrics tell you whether it mattered.
  • A model that improves offline but not online is common; knowing all three levels is how you catch it.

In the real world: A recommendation team's offline score improves for three releases in a row while online sales stay flat; they discover the offline test rewards popular items users would have bought anyway.

Visual example

Metric levels

Each level is slower and closer to what matters.

From the model to the business

  1. Model metricminutesNDCG, recall, error
  2. Product metricdaysBasket additions per session
  3. Business metricmonthsRevenue, retention, fraud loss
  4. GuardrailsalwaysLatency, complaints, cancellations

Reporting only the model metric. 'NDCG went up 3%' means nothing to the business until an experiment shows basket additions went up too, and that nothing on the guardrails got worse.

Practise it: Design an Image Search System

Online or batch prediction

What it is

Early on, decide when predictions are made:

  • Batch: compute predictions for everyone in advance, on a schedule, and store them. Tomorrow's forecast for every store.
  • Online: compute when the request arrives, using the latest information. The fraud score for this payment, now.

Many systems mix the two: batch for what changes slowly, online for what depends on the moment.

Why it matters

It is the decision that most shapes the architecture.

  • Batch is simpler, cheaper and easier to check before anyone sees it, but can only use what was known when the batch ran.
  • Online can use the current session and context, but needs fast features and a service that never goes down.
  • Module 18 covers the patterns in depth.

In the real world: Kirana Kart forecasts demand in batch every night, but scores fraud online at the moment of payment, because the card being used and the last few minutes of activity are what matter.

Defaulting to online for everything. If a prediction depends only on yesterday's data (a customer's monthly churn risk), computing it on every request costs money and adds failure points for no gain.

Constraints

What it is

Constraints remove options before any modelling starts:

  • Latency: the time budget for one prediction, inside the product's total budget.
  • Throughput: predictions a second at peak.
  • Cost: what the business will pay per thousand predictions, and for training.
  • Privacy and law: what data may be used, kept, or moved.
  • Explainability: whether decisions must be explained to customers or regulators.
  • Where it runs: a data centre, a phone, a device with no network.

Why it matters

A design that ignores a hard constraint is not a design.

  • A lender that must explain refusals cannot use an unexplainable model for the decision.
  • A phone keyboard's next-word model must fit in a few megabytes and run without the network.
  • Stating constraints out loud also protects you from over-building.

In the real world: Banks in many countries must give a reason when they refuse credit, which is why credit scoring often uses models whose decisions can be broken down feature by feature.

Discovering a constraint after building. A team builds a model on customers' location history and learns at launch review that the data may not be used for that purpose.

Practise it: Design a Recommendation System

Start with a baseline

What it is

A baseline is the simplest thing that could work. Build it first:

  • Rules: 'show the most popular products in the customer's city'.
  • Heuristics: 'ETA = travel time by distance + the store's average packing time'.
  • A simple model: logistic regression on five obvious features.

Every later model is judged by how much it beats the baseline.

Why it matters

Baselines are underrated.

  • They often deliver most of the value: 'popular in your area' is a strong recommender.
  • They tell you whether ML is worth it: if a complex model beats the rule by 1%, the upkeep may not pay.
  • They are the fallback when the model fails.
  • They make the whole pipeline work end to end before the hard part starts.

In the real world: Google's Rules of ML guide advises shipping a simple heuristic first, then a simple model, and only then a complex one, so that each step's gain is visible.

Comparing a new model only with the previous model, never with a simple rule. A team discovers its neural recommender is 2% better than 'popular items', at fifty times the cost.

A prediction is not yet a decision

What it is

The model outputs a prediction; the product takes an action. Between them sits a decision layer:

  • thresholds: 'block above 0.9, review between 0.6 and 0.9';
  • business rules: 'never recommend alcohol to under-21 accounts';
  • limits: 'at most two promoted items in the top ten';
  • costs: 'review only as many as the team can handle today'.

Why it matters

Keeping the two separate makes the system easier to change.

  • The business can change a threshold or a rule today, without retraining.
  • The model stays focused on predicting well; policy lives in code people can read.
  • It is also where legal and safety requirements are enforced reliably.

In the real world: Kirana Kart's fraud model outputs a probability; a separate rules service turns it into allow, review or block, using thresholds the risk team changes weekly.

Training the model to make the policy decision itself. If 'review capacity is 500 a day' is baked into the labels, the model must be retrained every time the team grows.

Interview questions: framing an ML problem

What it is

The questions interviewers ask about framing an ML problem, from the first screening call to the senior round. Cover the answer, say yours aloud, then compare.

Why it matters

Reading an idea and explaining it are different skills.

  • Each answer below is the two or three sentences an interviewer is listening for.
  • The reasoning behind each one is in the cards above. If an answer surprises you, go back to that card.

In the real world: In ML design interviews, the first five minutes are scored as 'problem understanding'. Candidates who state a precise target and metric score well even if their model choice is ordinary.

Q: How do you start an ML system design question?

With the business goal and clarifying questions: users and scale, latency, what data and labels exist, and constraints. Then I state the prediction target and the success metric before mentioning any model.

Q: How do you choose what to predict?

A target that is tied to the goal, observable so I get labels, available soon enough to train on, and precisely defined with a time window. For example, 'added to basket in this session' rather than 'liked'.

Q: What is a proxy metric, and what is its risk?

A measurable stand-in for the real goal, like clicks for satisfaction. The risk is that optimising it diverges from the goal, so I pair it with guardrail metrics and check the business metric in experiments.

Q: Why build a baseline first?

It sets the bar a model must beat, often delivers much of the value, gives a fallback when the model fails, and proves the pipeline works end to end.

Q: When would you choose batch over online prediction?

When predictions depend only on slowly changing data and can be computed ahead of time; it is cheaper and simpler. Online when the prediction needs the current request or session.

Q: Why separate the model from the decision?

So thresholds and business rules can change without retraining, policy is readable and auditable, and the model's job stays simply predicting well.

Naming the model before the target. 'I'd use a transformer' is not an answer to 'how would you increase basket size?'.

Exercise: frame three problems

What it is

A short build that uses this module's ideas. Write it yourself before looking anything up; the checks at the end tell you whether it works.

Why it matters

An idea you have only read fades in a week.

  • Building it once, even in fifty lines, is what makes it yours.
  • Interviewers can tell the difference between someone who has read about a loop and someone who has debugged one.

In the real world: Product teams at many companies write a short 'ML problem statement' like this before any engineering starts; it is the most reviewed page of the project.

Your task. Write a one-paragraph framing for three different business goals, using the same template each time.

Steps

  1. Choose three goals, for example: 'reduce late deliveries', 'reduce customer churn', 'help sellers price products'.
  2. For each, write: the business metric, the prediction target (with its time window), the task type, the label source and its delay.
  3. List two alternative framings for each and say in one sentence why you rejected them.
  4. Write a rule-based baseline for each.
  5. Decide batch or online for each, with a reason.
  6. Name one guardrail metric for each.

You are done when

  • Every target is observable and has a stated delay before its label arrives.
  • Every problem has a baseline that could ship next week without ML.
  • A friend reading your framing could say exactly what the model outputs.

Stretch. For one problem, describe a proxy metric that would go up while the business metric went down.