productinterview.tools
MenuClose

AI Numbers: Serving Latency, Throughput and Cost per Token

Throughput, latency and cost per token.

Advanced3 lessons5 questions

What this module covers

  • The two phases of generating a response, and which one users feel
  • The trade-off between serving many users cheaply and serving each one fast
  • KV cache memory, worked through with numbers
  • Estimating serving cost from GPUGraphics processing unit. The chips most AI models are trained and served on. Read the full explanation price and throughput
AI numbers: serving, cost and latency

Why it matters, by role

  • AI Infrastructure PMProduct Manager. Decides what a product should do, for whom, and why. Read the full explanation: these numbers are the job.
  • AI TPMTechnical Program Manager. Owns plans, dependencies, risks and delivery for large cross-team programmes. Read the full explanation: capacity plans depend on throughput and memory.
  • AI Platform PM: pricing and rate limits rest on serving cost.
  • Forward Deployed EngineerForward Deployed Engineer. An engineer embedded with customers who scopes, builds and ships AI solutions into production. Read the full explanation: customers ask why it's slow and what it will cost at their volume.

Lessons

  1. Where latency comes from
  2. The KV cache and batching
  3. Estimating cost per token

Where latency comes from

Generating a response has two phases:

  1. Prefill: the model reads the whole input at once. Longer prompts take longer. This sets the time to first token, how long users wait before anything appears.
  2. Decode: the model produces output one token at a time. Each token needs the model's weights read from memory, so speed is limited by memory bandwidth more than raw compute. This sets the time per output token.

So total time ≈ time to first token + (output tokens × time per token). Two practical consequences: long outputs are slow, whatever the input; and streaming helps users because they see progress during decode.

The KV cache and batching

During decode the model stores the attention keys and values for every token so far, so it doesn't recompute them. This is the KV cache, and it uses a lot of memory:

per token ≈ 2 (keys and values) × layers × KV heads × head size × bytes per value

For a 70B-class model with 80 layers, 8 KV heads of size 128, at 16-bit (2 bytes): 2 × 80 × 8 × 128 × 2 ≈ 330 KB per token. A 4,000-token conversation needs about 1.3 GB of cache; 100 such conversations at once need about 130 GB, on top of the weights.

Batching serves many requests together, so the weights are read once for many users. Bigger batches raise throughput (tokens per second across all users) and lower cost, but each user waits a little longer. Modern servers add and remove requests from the batch continuously. KV cache memory is often what limits batch size.

Estimating cost per token

A simple method:

  1. GPU cost per hour: say $2–4 for a rented data-centre GPU (it varies widely; state your assumption).
  2. Throughput: tokens per second the GPU produces across all requests, at the latency you've promised. Say 1,000 output tokens per second.
  3. Tokens per hour: 1,000 × 3,600 = 3.6 million.
  4. Cost per million tokens: $2 ÷ 3.6 ≈ $0.55 at $2/hour; about $1.10 at $4/hour.

Then adjust for reality: GPUs aren't fully used around the clock, larger models need several GPUs, and tighter latency targets mean smaller batches and higher cost. In an interview, the method and stated assumptions matter more than the exact figure.

Questions

Rubric

Dimension Weak Passable Strong
Latency "The model is slow" Input vs output length Prefill vs decode, time to first token vs per-token speed
Memory Weights only Knows the KV cache exists Estimates KV cache size and how it limits batch size
Trade-offs Ignores them Throughput vs latency Batching, cost and latency targets traded explicitly
Cost Guesses GPU price ÷ throughput Full method with stated assumptions and utilisation

Next modules