Skip to content
mlmentorship

Design an ML system under a fixed serving budget

A cost-constrained system-design question where quality, latency, traffic, and annual spend must fit one defensible operating point.

Published · 61 min read ·Core ·Advanced

ML system design · active recall

Practice before you read

40 minutes. Scope first; then cover data, baseline, model, evaluation, serving, monitoring, and iteration.

ML system design · closed-book attempt

Design an ML system under a fixed serving budget

Scope first; then cover data, baseline, model, evaluation, serving, monitoring, and iteration.

Problem

Context. The hypothetical product has 20 million daily users, a $3 million annual serving budget, and an 80 ms p95 limit. Requests per user, peak traffic, catalog size, and infrastructure prices are not yet specified. Task. State assumptions, estimate traffic and allowable unit cost, and choose retrieval, ranking, caching, and fallback stages. Show a feasible budget and a measurement plan, or identify which requirement must change. Constraints. Daily users are not requests per second; separate averages, peaks, and tail latency. Include replicated capacity, data access, and operating overhead within the declared budget boundary rather than counting accelerator inference alone.

40:00recommended time

Closing or reloading clears the scratchpad. Only score, weak rubric dimensions, attempt count, and retry date can be stored locally.

30-second answer map

Trace how a narrowing ranking funnel reserves expensive scoring for fewer candidates while every request remains inside one end-to-end latency ceiling and one unit-cost ceiling.

Spend expensive scoring only after shrinking the candidate set

Spend expensive scoring only after shrinking the candidate setExplicitly illustrative candidate counts shrink from 10,000 to 1,000 to 100. Widths communicate ordered narrowing rather than a linear count scale. The separate request-level target remains p95 below 80 milliseconds and cost at most 0.08 dollars per 1,000 requests. Stage p95s are not added as if they were request p95.Illustrative counts, not measured stagelatenciesretrieve10,000 candidatespre-rank1,000 candidatesfinal rank100 candidatesWidths show narrowing, not a linear countscale.Measure request p95 < 80 ms and cost <= $0.08 /1K.Overload: fewer candidates or a boundedfallback.
Read it this way: The counts are illustrative, and funnel widths are schematic. Measure latency and cost for the whole request. Under overload, reduce work or use fallback.
Check: Where should expensive work be spent? Which work can be removed before exceeding the shared request budget?
Full interview answer 61 min read
Reading depth

Design a personalized ranking system for 20 million daily users. The serving budget is $3 million per year and p95 latency must stay below 80 ms. What do you ship?

Design a personalized ranking service that fits an explicit annual serving budget and request-latency requirement.

Problem

Context. The hypothetical product has 20 million daily users, a $3 million annual serving budget, and an 80 ms p95 limit. Requests per user, peak traffic, catalog size, and infrastructure prices are not yet specified.

Task. State assumptions, estimate traffic and allowable unit cost, and choose retrieval, ranking, caching, and fallback stages. Show a feasible budget and a measurement plan, or identify which requirement must change.

Constraints. Daily users are not requests per second; separate averages, peaks, and tail latency. Include replicated capacity, data access, and operating overhead within the declared budget boundary rather than counting accelerator inference alone.

Clarify before calculating

Ask how many requests each user makes, how traffic peaks and what the annual budget includes. Also define quality, freshness, availability and fallback requirements. These determine which operating points are allowed.

Build an order-of-magnitude model

Assume five requests per daily user: 100 million requests per day. Use 365 days and a fivefold peak factor for this example.

QuantityCalculationResult
Average requests/secondAbout 1,157
Assumed peakAbout 5,787 requests/second
Annual requests36.5 billion
Daily budgetAbout $8,219
Unit ceilingAbout $0.08219 per thousand

The unit ceiling covers the declared budget scope, not just model kernels. Subtract included feature, logging, storage and operational costs before allocating inference spend. Excluded costs still belong in a separately reported total.

Traffic sets the cost ceiling; cheaper scoring still needs quality and latency evidence

Traffic sets the cost ceiling; cheaper scoring still needs quality and latency evidenceAssumptions turn users into requests and budget into a unit ceiling. Filter before expensive scoring; lost recall stays lost. At unchanged unit cost, doubled traffic doubles annual spend. A cheaper route can recover cost feasibility only. Measure quality, freshness and end-to-end tail latency under peak load. Include scoped overhead and fallback costs.Declare the workload before choosinghardware20 million users; five requests eachday100 million requests/day; 36.5billion/yearAverage 1157 requests/s; assumed peak5787Full-scope budget: $3 million peryearOriginal unit ceiling$0.08219 per thousand requestsDoubled traffic; unchanged budget$0.04110 per thousand requestsReduce work; retain upstreammembershipEach fixed mark: twenty candidatesRetrieved: 10000Shortlist: 200Scored: 20Gray marks were removed; finalscoring cannot recover them.Compare complete annual cost on onescaleOriginal traffic; $0.06 per thousand$2.19 million: cost fits onlyDouble traffic; same $0.06$4.38 million: budget failsDouble traffic; proposed $0.04$2.92 million: cost fits onlyDashed annual limit: $3 millionThe cheaper proposal is not ameasured product pointUseful quality andfreshness?End-to-end p95 below 80 msat peak?Measure router, queue, feature,fallback and replication costs. Stagecounts are not tail-latency evidence.
Read it this way: Assumptions turn users into requests and budget into a unit ceiling. Filter before expensive scoring; lost recall stays lost. At unchanged unit cost, doubled traffic doubles annual spend. A cheaper route can recover cost feasibility only. Measure quality, freshness and end-to-end tail latency under peak load. Include scoped overhead and fallback costs. Does a cheaper route alone qualify shipment?
Reference drawing

Traffic sets the cost ceiling; cheaper scoring still needs quality and latency evidence

Traffic sets the cost ceiling; cheaper scoring still needs quality and latency evidenceAssumptions turn users into requests and budget into a unit ceiling. Filter before expensive scoring; lost recall stays lost. At unchanged unit cost, doubled traffic doubles annual spend. A cheaper route can recover cost feasibility only. Measure quality, freshness and end-to-end tail latency under peak load. Include scoped overhead and fallback costs.Declare the workload before choosinghardware20 million users; five requests eachday100 million requests/day; 36.5billion/yearAverage 1157 requests/s; assumed peak5787Full-scope budget: $3 million peryearOriginal unit ceiling$0.08219 per thousand requestsDoubled traffic; unchanged budget$0.04110 per thousand requestsReduce work; retain upstreammembershipEach fixed mark: twenty candidatesRetrieved: 10000Shortlist: 200Scored: 20Gray marks were removed; finalscoring cannot recover them.Compare complete annual cost on onescaleOriginal traffic; $0.06 per thousand$2.19 million: cost fits onlyDouble traffic; same $0.06$4.38 million: budget failsDouble traffic; proposed $0.04$2.92 million: cost fits onlyDashed annual limit: $3 millionThe cheaper proposal is not ameasured product pointUseful quality andfreshness?End-to-end p95 below 80 msat peak?Measure router, queue, feature,fallback and replication costs. Stagecounts are not tail-latency evidence.
Derivation
Spend expensive scoring only after shrinking the candidate setExplicitly illustrative candidate counts shrink from 10,000 to 1,000 to 100. Widths communicate ordered narrowing rather than a linear count scale. The separate request-level target remains p95 below 80 milliseconds and cost at most 0.08 dollars per 1,000 requests. Stage p95s are not added as if they were request p95.Illustrative counts, not measured stagelatenciesretrieve10,000 candidatespre-rank1,000 candidatesfinal rank100 candidatesWidths show narrowing, not a linear countscale.Measure request p95 < 80 ms and cost <= $0.08 /1K.Overload: fewer candidates or a boundedfallback.
Read it this way: The counts are illustrative, and funnel widths are schematic. Measure latency and cost for the whole request. Under overload, reduce work or use fallback.
Check: Where should expensive work be spent? Which work can be removed before exceeding the shared request budget?
Read it this way: Assumptions turn users into requests and budget into a unit ceiling. Filter before expensive scoring; lost recall stays lost. At unchanged unit cost, doubled traffic doubles annual spend. A cheaper route can recover cost feasibility only. Measure quality, freshness and end-to-end tail latency under peak load. Include scoped overhead and fallback costs. Does a cheaper route alone qualify shipment?

A defensible architecture progression

Start with a heuristic, linear or tree baseline. Measure a quality, cost and latency point before adding stages. For an illustrative funnel, retrieval keeps 200 of 10,000 candidates; the final ranker scores 20 of those 200. Measure retrieval recall: no final ranker can recover a relevant item already discarded.

Precompute stable embeddings and reuse candidates when their age is acceptable. Batch only within the latency limit. Test quantization or distillation against the measured bottleneck. They can reduce work without improving latency if another stage dominates.

Measure end-to-end p95 under representative peak load, including queueing, features, network calls and fallbacks. Adding stage p95 values does not produce the request’s p95. Track per-stage work and cost to explain the total.

Change the operating point

1. Only 5% of requests benefit from expensive ranking

New task: concentrate extra work where it improves the outcome.

Picture and change: put a router before the expensive branch. Measure missed opportunities and segment quality as well as the fraction routed. Include router cost and shared work.

Check: 5% observed use does not prove that the other 95% never benefits.

Use when: measured marginal value differs across requests.

2. The cache meets cost but returns stale candidates

New task: retain useful results as items and users change.

Picture and change: include versioned keys, invalidation and an age limit. Measure outcome quality by age, plus miss and fallback cost.

Check: a high hit rate can coexist with unacceptable freshness.

Use when: reuse trades computation against changing eligibility or relevance.

Try doubled traffic

Traffic doubles without a budget increase. What happens to the unit ceiling?

Check your answer

It halves to about $0.04110 per thousand requests. Peak capacity must also be retested. The old operating point no longer proves feasibility.

Check a hardware proposal

“Use a two-tower model and autoscale GPUs” does not supply a capacity or cost calculation. Record workload shapes, current prices, utilization, batching limits and availability reserves. Autoscaling cannot make an unaffordable peak fit the budget.

Choose a feasible point

Compare quality, full cost and end-to-end tail latency under the same traffic assumptions. Include a measured degraded path, rollout limit and rollback trigger. Use cost per useful outcome alongside cost per request.

Compare further investment

Test better candidate generation against a larger ranker. Compare building infrastructure with buying capacity, including maintenance and price changes. Stop adding work when its measured value no longer justifies its cost.

Evidence for a recommendation

A claimed 1% conversion gain at triple cost needs a causal value estimate and actual cost accounting. Check uncertainty, cheaper alternatives and the hard budget before recommending shipment.

Failure cases

A larger final model cannot repair retrieval that dropped every relevant item. An inference-only spreadsheet cannot establish total serving cost.

Common follow-ups

  • Traffic doubles with no budget increase. What changes first?
  • The largest model adds 1% conversion but triples cost. Do you ship it?
  • How do prefill and decode change the cost model for an LLM ranker?
  • What if only 5% of requests need personalization?
  • How do you detect that caching is silently harming freshness?

Related: reduce LLM inference cost 10×, GPU memory hierarchy, and quantization.