Cost, latency, and scaling for AI features: tokens, caching, model routing
The system-level levers that keep AI features fast and affordable as usage grows, and how to reason about them in interviews.
On this page
AI features have a cost profile unlike most software: every request costs real money, takes noticeable time, and scales directly with usage. A feature that's cheap in a demo can become a top-three cost line at a million users. This lesson covers the architecture levers; the AI PM track's cost lesson covers the product side.
Why interviewers ask this
"Our AI feature is too slow and too expensive. What do you do?" and "How would this design scale to 10 million users?" are common in AI system design rounds. Interviewers want structured reasoning: what drives cost and latency, which levers exist, and how to use them without hurting quality.
The framework
1. Know the drivers
- Tokens: cost ≈ (input tokens × input price) + (output tokens × output price). Long prompts, large retrieved contexts, long conversation histories and verbose outputs all add up. Output tokens are usually pricier and slower.
- Requests: how many calls per user action? Agents and multi-step chains can make five to twenty.
- Model size: bigger models are usually better, slower and more expensive.
- Latency: time to first token (how long before anything appears) and total generation time (which grows with output length).
2. The levers
flowchart LR
R["Request"] --> C{"Cached answer?"}
C -->|yes| A["Return instantly"]
C -->|no| RT{"Router: how hard?"}
RT -->|simple| S["Small fast model"]
RT -->|complex| L["Large model"]
S --> ST["Stream tokens to user"]
L --> ST- Model routing: classify requests and send easy ones to a small, cheap model; escalate hard ones. Often the biggest saving.
- Caching: cache answers to repeated questions, and use prompt caching for long, repeated context (system prompts, documents), which providers discount heavily.
- Trim context: fewer and better retrieved chunks, summarised history instead of the full transcript, and concise output formats.
- Streaming: show tokens as they're generated, which cuts perceived latency dramatically.
- Async and batch: run non-urgent work (summaries, tagging) in the background, often at batch discounts.
- Product limits: usage caps, rate limits, and paid tiers for heavy users.
- Fewer calls: combine steps, or replace model calls with rules where possible.
3. Scaling concerns
- Provider rate limits: plan quotas with your provider before launch; have fallbacks (another model or provider) for outages.
- Peak traffic: queue non-urgent requests, and degrade gracefully (shorter answers, smaller model) under load.
- Unit economics: cost per active user and cost per successful outcome must stay below the value created, which is the margin question for pricing.
4. Always measure with evals
Every cost or latency change risks quality. Run the eval set on any model switch, prompt trim or routing change.
Worked example
Question: "Our AI writing assistant costs $1.20 per active user per month and p95 latency is 9 seconds. Usage is growing 20% a month. What would you do?"
Sample answer:
"I'd break the problem into cost drivers and latency drivers, then pull the levers in order of impact and risk, with evals protecting quality.
Diagnose: what's a typical request? Suppose we send the whole document (6,000 tokens) plus a long system prompt on every suggestion, always use the largest model, and generate 600 tokens. And 40% of requests are simple: fix grammar, shorten a sentence.
Levers:
- Routing: send simple edits (grammar, shorten, tone) to a small model. If 40% of traffic moves to a model that's ten times cheaper, that alone cuts about a third of cost, and those requests get much faster.
- Trim context: send only the paragraph being edited plus a short document summary instead of the whole document. Maybe 60% fewer input tokens.
- Prompt caching for the system prompt and document summary, which repeat across requests.
- Streaming, so the first words appear in under a second, even when the full response takes longer.
- Shorter outputs where possible: return the edited sentence, not an explanation.
Guardrails: acceptance rate of suggestions and our eval scores must stay flat. I'd roll out each change behind a flag and compare.
Target: under $0.40 per active user and p95 time to first token under 1.5 seconds. I'd also check provider rate limits against our growth curve for the next six months, so we don't hit a wall."
Common mistakes
- Using the biggest model for everything.
- Sending the entire document or history on every request.
- Ignoring time to first token when talking about latency.
- Optimising cost without evals.
- Forgetting provider rate limits and outages in scaling plans.
Interviewer tips
What "great" sounds like:
- "Cost is tokens times price times requests. Let's find which one is driving it."
- "Route simple requests to a small model, escalate the hard ones."
- "Streaming fixes perceived latency even when total time stays the same."
- "Every change is gated by our eval set and acceptance rate."
- "I'd track cost per successful outcome, not just per request."
Practice questions
Answer one in a mock interview and get graded instantly.
1.Our AI writing assistant costs $1.20 per active user per month and is slow. What would you do?
Practice this →2.Explain model routing and when it's worth the added complexity.
Practice this →3.How would you prepare an AI feature for 10x more users next quarter?
Practice this →
Finished reading?
