ML System Design · Module 4 of 47 · 11 concepts · about 15 min

Requirements, Scale and Estimates

Turning a framed problem into numbers: requests a second, storage, training data size, the latency budget, how many machines serving needs, availability and cost. Quick, rough arithmetic that rules designs in or out.

At work: Capacity planning for any ML launch, and the 'how big is this?' part of a design interview. Rough numbers stop a team from building something that cannot possibly be fast or cheap enough.

Functional and non-functional requirements

What it is

Requirements come in two kinds:

  • Functional: what the system does. 'Show ten recommended products on the home screen'; 'score every payment for fraud'.
  • Non-functional: how well it must do it. Latency, throughput, availability, freshness, cost, privacy.

For ML systems add two more non-functional ones: how fresh the data behind a prediction must be, and how quickly a new model must reach production.

Why it matters

Non-functional requirements decide the architecture.

  • 'Recommendations' could be a nightly batch job or a live service; '100 ms, using what the user did in the last minute' decides which.
  • Writing both kinds down gives every later decision something to be checked against.

In the real world: A design review at a payments company rejects a fraud proposal in five minutes because it has no stated latency: the payment network allows only a fixed time for a decision.

Listing only functional requirements. Two systems that both 'recommend products' can differ by a factor of a hundred in cost because one needed live features and the other did not.

Why estimate

What it is

A back-of-the-envelope estimate is quick arithmetic with round numbers to find the size of a problem:

  • how many requests a second;
  • how much data a day, and in total;
  • how many machines, and roughly what it costs.

Being within a factor of two or three is good enough. The goal is to know whether something is a laptop, a server or a data centre.

Why it matters

Scale changes the design.

  • 10 requests a second can be served by one small service; 100,000 needs caching, batching and many machines.
  • A training set of 1 GB fits in memory; 10 TB needs distributed processing.
  • Interviewers expect a few estimates, done aloud, early in the design.

In the real world: An estimate that a feature store would need 4 TB of memory for every user's features sends a team back to keep only active users' features online, cutting it to 300 GB.

Precise arithmetic on made-up numbers. Round everything (a day is about 100,000 seconds), say your assumptions, and spend the time on what the numbers imply.

Requests per second

What it is

Start from daily volume and convert:

  • average requests a second = requests a day ÷ 86,400 (about 100,000);
  • peak = average × a peak factor, often 2 to 5 for consumer apps (evening rush, sales);
  • for ranking, multiply by the items scored per request: that is the model's real workload.

Why it matters

Design for the peak, not the average.

  • A service sized for the average falls over every evening.
  • The fan-out multiplier is what surprises people: a few hundred requests a second, each scoring 500 items, is over a hundred thousand model evaluations a second.

In the real world: Kirana Kart's busiest hour is the evening, at about three times the day's average. Its forecasts run as one nightly job instead, so they have no per-second rate at all.

Visual example

Computed

Kirana Kart's ML features, from daily volume to peak requests a second (peak = 3 × average).

Illustrative volumes. 86,400 seconds in a day.
featurerequests a dayaverage a secondpeak a second
Recommendations8,000,00092.6278
Search ranking3,000,00034.7104
Delivery time10,000,000115.7347
Fraud scoring630,0007.322
Demand forecasts20,000,000 a nightbatchbatch

Fan-out for recommendations

peak: 278 requests a second at peak

fan: × 500 candidates scored per request

total: = 138,889 product scores a second

Forgetting fan-out. 'Only 280 requests a second' sounds small until each one ranks 500 products.

Storage estimates

What it is

Estimate storage from events a day × bytes per event × days kept:

  • count each kind of event: items shown, clicks, additions to basket, searches;
  • assume a size per event (a few hundred bytes for an ID-heavy log line);
  • multiply by how long you keep it.

Why it matters

Logging is where ML data comes from, and it grows fast.

  • Impressions (items shown) dominate: every screen shows many items, and each must be logged to know what was not clicked.
  • The total decides where data lives: a database, a data warehouse or cheap object storage.

In the real world: Most companies keep raw event logs in cheap object storage (such as Amazon S3) for a year or more and summarised tables in a warehouse for daily use.

Visual example

Computed

Kirana Kart's interaction log at 200 bytes an event. Items shown are nine-tenths of it.

Illustrative: 20 items shown per home-screen view
eventa dayshare
Items shown (impressions)160,000,00092%
Clicks8,000,0004.6%
Added to basket3,000,0001.7%
Searches3,000,0001.7%
Total174,000,000100%

Bytes

day: 174,000,000 × 200 B = 34.8 GB a day

year: × 365 = 12.7 TB a year, before compression

Not logging impressions to save space. Without a record of what was shown and ignored, there are no negative examples, and the recommender cannot be trained (module 5).

Training data size

What it is

Estimate the training set from the labels you will use:

  • positive examples a day (additions to basket);
  • negative examples a day (items shown and not added), usually sampled down, because there are far too many;
  • × the days of history used;
  • × features per row × bytes per feature.

Why it matters

The size decides how training runs.

  • Under a few gigabytes: one machine, in memory.
  • Hundreds of gigabytes: a big machine reading from disk, or a small cluster.
  • Terabytes: distributed training (module 15).
  • It also shows why sampling negatives is standard: keeping them all would be ten times bigger and teach little more.

In the real world: Large ad and recommendation systems train on billions of rows and routinely keep only a small percentage of the non-clicked examples.

Visual example

Computed

Kirana Kart's recommender: 30 days of history, 10% of negatives kept, 100 features of 4 bytes.

Training rows for the 'added to basket' model
a dayover 30 days
Positives (added)3,000,00090,000,000
Negatives kept (10% of 157,000,000)15,700,000471,000,000
Rows18,700,000561,000,000
Size7.5 GB224.4 GB

Too big for one machine's memory, small enough for a single large machine reading from disk or a small cluster.

Sampling negatives without correcting for it. The model's predicted probabilities will be too high by the sampling factor unless the scores are re-scaled (module 7).

Latency budgets

What it is

A latency budget splits the time allowed for one request among its steps:

  • start from the product's total limit (the whole screen must load in, say, 300 ms);
  • give the ML part a share of it;
  • divide that share among network, feature fetching, retrieval, the model and post-processing;
  • measure each step at the 95th or 99th percentile, not the average: the slow requests are the ones users notice.

Why it matters

The budget decides what is possible.

  • If the ranking model has 40 ms for 500 items, a large neural network is out unless it is made faster.
  • Feature fetching is often the surprise: ten separate database reads can use the whole budget.
  • Every step that is added must take time from another.

In the real world: Amazon has long reported that every 100 ms of added page delay costs measurable sales, which is why recommendation services there are held to strict time budgets per step.

Visual example

Computed

Kirana Kart's home-screen recommendations: a 100 ms budget at the 99th percentile, out of 300 ms for the whole screen.

Illustrative split. Each step is measured at p99.
stepmssharewhat happens
Network and request handling2020%Into the service and back out
Fetch user and context features1515%One batched read from the online store
Candidate retrieval2020%Find ~2,000 products; a light model keeps ~500
Ranking model4040%Score all ~500 candidates in one batch
Business rules and re-ranking55%Filter out-of-stock; mix in variety
Total100100%

Budgeting with averages. A step that averages 10 ms but takes 80 ms for one request in a hundred will blow the budget for about ten thousand home-screen requests an hour at Kirana Kart's evening peak.

Throughput and how many machines

What it is

To size a prediction service:

  • measure how many requests one copy (replica) handles a second at the latency you need;
  • divide peak requests a second by that;
  • add headroom (often 30% or more) for spikes, slow machines and a copy being replaced;
  • round up, and never go below two copies, so one can fail.

Why it matters

Too few replicas and the service slows down or drops requests at peak; too many and you pay for idle machines.

  • Measuring one replica under realistic load is the only reliable starting point.
  • Autoscaling adds and removes copies as traffic changes (module 19), but it still needs a sensible minimum.

In the real world: Kirana Kart load-tests one copy of its ranking service with real requests of 500 candidates and finds it holds 50 requests a second inside the 40 ms budget.

Visual example

Computed

Sizing the ranking service: 8 replicas at peak.

One replica: 50 requests a second at p99 under 40 ms. Headroom 30%.
inputvalue
Peak requests a second278
Usable per replica50 × 0.7 = 35
Replicas needed278 ÷ 35 → 8

Sizing from a benchmark with tiny requests. A replica that handles 500 requests a second scoring 10 items may handle 50 scoring 500 items.

Availability and the fallback

What it is

Availability is the share of time a service answers correctly. Each extra 'nine' cuts the allowed downtime by ten:

  • 99% allows several days of downtime a year;
  • 99.9% allows under nine hours;
  • 99.99% allows under an hour.

For ML features the key design question is: what does the product do when the model cannot answer?

Why it matters

An ML feature should almost never take the product down with it.

  • If recommendations fail, show popular items.
  • If the ETA model fails, show the simple distance-based estimate.
  • If fraud scoring fails, decide in advance whether to let payments through (fail open) or hold them (fail closed).
  • A good fallback means the model can have lower availability than the product.

In the real world: Many payment companies fail open for small, low-risk payments and closed for large ones when the fraud model is unreachable, because blocking every payment costs more than a few minutes of extra fraud.

Visual example

Computed

365 days a year. Every extra nine costs much more to achieve.

Downtime a year at each availability target
targetdowntime a year
99%3.65 days
99.9%8.76 hours
99.99%52.6 minutes

No fallback. The model service has a bad deploy and the home screen shows an error instead of products, so a recommendation outage becomes a sales outage.

Practise it: Debug a Production ML Model, Design a Search Ranking System

Estimating cost

What it is

Estimate serving cost from the replica count:

  • replicas × price per machine-hour × hours in a month;
  • divide by requests a month for cost per thousand predictions;
  • add training (machine-hours per run × runs a month), storage and data processing.

Compare the result with the value of the feature: extra revenue, fraud prevented, waste avoided.

Why it matters

Cost is a requirement, not an afterthought.

  • A model that adds ₹1 lakh a month in sales but costs ₹3 lakh to serve should not ship.
  • Cost per thousand predictions makes options comparable: a bigger model, a GPU, or precomputing in batch.

In the real world: A team moves its product-similarity model from per-request scoring to a nightly batch that stores the top 50 similar items per product, cutting serving cost by over 90% with no visible change to users.

Visual example

Computed

Serving cost of the ranking service: ₹2.3 lakh a month, about ₹0.96 per thousand recommendations.

Illustrative: ₹40 a machine-hour, 30-day month
inputvalue
Replicas8
Machine-hours a month5,760
Cost a month₹2.3 lakh
Requests a month240,000,000
Per thousand requests₹0.96

Autoscaling down at night would lower this further, since traffic at 3 a.m. is a fraction of the peak.

Counting only the model servers. Feature stores, streaming jobs and data warehouses often cost more than the model itself.

Interview questions: requirements and estimates

What it is

The questions interviewers ask about requirements and estimates, 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: Interviewers often interrupt with 'how many machines is that?' Candidates who can produce a rough number in thirty seconds, with stated assumptions, keep control of the conversation.

Q: Why estimate scale in an ML design?

Because scale changes the design: requests a second decide serving, fan-out decides model size, data volume decides how training runs. Rough numbers rule options in or out early.

Q: How do you estimate peak requests a second?

Daily requests divided by about 86,400 for the average, times a peak factor of two to five. For ranking, multiply by the candidates scored per request to get the real model load.

Q: How would you split a 100 ms latency budget?

Network and overhead, feature fetching, candidate retrieval, the model, and post-processing, each measured at p99. Feature fetching is often the hidden cost, so batch those reads.

Q: How many replicas does a service need?

Peak requests divided by what one replica handles at the required latency, plus 30% or more headroom, rounded up, never fewer than two.

Q: What happens when the model is down?

A fallback: a simpler model, cached results, popular items or a rule. For fraud, decide in advance whether to fail open or closed, often by transaction size.

Q: Why log impressions if they take most of the storage?

Because items shown and not chosen are the negative examples; without them you cannot train or evaluate a ranking model, and you cannot correct for what users never saw.

Spending ten minutes on arithmetic. Two or three estimates that change decisions are enough.

Exercise: estimate a system you know

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: Senior engineers write a version of this sheet before any large launch; it is what finance and infrastructure teams ask for first.

Your task. Produce a one-page estimate sheet for an ML feature of a large app (a video feed, a ride's arrival time, a marketplace's search).

Steps

  1. State assumptions: daily active users, sessions per user, predictions per session.
  2. Compute average and peak requests a second, and the fan-out if it ranks items.
  3. Estimate event-log size a day and a year, including impressions.
  4. Estimate training rows and bytes for 30 days, with negative sampling.
  5. Write a latency budget with at least four steps that sums to the total.
  6. Size the serving fleet with headroom and estimate the monthly cost.

You are done when

  • Every number traces back to a stated assumption.
  • The latency budget sums exactly to the total.
  • You can say which single assumption, if wrong, would change the design most.

Stretch. Redo the cost assuming you precompute predictions nightly for active users instead of serving live, and compare.