Free preview

The Estimation That Matters: GPUs and Tokens

Why this matters: the previous lesson established that every resource the standard template measures is negligible here. This lesson computes the one that is not. Nothing else in the chapter constrains the design as tightly as what follows.

Step one: convert requests into tokens

The estimation cannot proceed in requests, because a request is not a unit of work here. The unit is a token — roughly three quarters of an English word, or about four characters.

Response size          = 5 KB
Tokens per response    = 5,000 chars / 4 chars per token  = 1,250 tokens
Aggregate token rate   = 17,361 req/s x 1,250 tokens      = 21.7 M tokens/second

Step two: prefill and decode are different workloads

Generating a response has two phases with completely different performance characteristics.

PrefillDecode
What it doesProcesses the entire promptGenerates output tokens one at a time
ParallelismAll prompt tokens at onceStrictly sequential — token N needs token N-1
Forward passesOneOne per output token — 1,250 of them
BottleneckCompute (FLOPs)Memory bandwidth
DeterminesTime to first tokenTime per output token
GPU utilizationHigh — the hardware is busyLow — the hardware waits on memory

Step three: the KV cache, and why it bounds everything

If large batches are free throughput, why not batch a thousand sequences? Because each one occupies memory that grows with the conversation.

Step four: size the fleet

Aggregate demand    = 21.7 M tokens/second
Per-GPU throughput  = ~2,000 tokens/second (batched, mid-size model)
GPUs required       = 21.7M / 2,000 = about 10,900 GPUs
Per-GPU throughputGPUs needed
1,000 tok/s21,700
2,000 tok/s10,900
4,000 tok/s5,400

Step five: the scheduling problem

Fixed batching wastes enormously here, for a reason specific to generation: sequences in a batch finish at different times. One user asks for a word, another for an essay. With static batching the whole batch waits for the longest.

Key takeaway

The unit of work is a token, and 17,361 requests per second is 21.7 million tokens per second. Generation splits into prefill — one parallel, compute-bound pass over the prompt, setting TTFT — and decode, 1,250 sequential, memory-bandwidth-bound passes setting TPOT. Because decode must read all 140 GB of weights per token, a single sequence is capped near 24 tokens/second, and batching multiplies throughput at no cost to per-user speed — which makes it the difference between viable and impossible. The limit on batch size is the KV cache, which grows linearly with context and can leave room for only a dozen sequences. The fleet is roughly 10,900 GPUs against 0.27 web servers, and that ratio is the design: every good decision moves work from the expensive side to the cheap one.

Interview signal by level

LevelWhat a strong answer sounds like
L4"We need GPU servers for inference and we'd scale them horizontally behind a load balancer."
L5Converts to tokens and knows the phases: "the unit is tokens, not requests — 21.7M tokens per second. Prefill processes the prompt in one pass and sets time-to-first-token; decode is sequential and sets the pace after. We batch to keep GPUs busy and stream tokens so users see output immediately."
Staff+Derives the bottleneck: "decode is memory-bandwidth bound — every token requires reading all 140 GB of weights, capping a single sequence near 24 tokens per second. Batching amortizes that read, so throughput scales with batch size at constant per-user speed. The limit is KV cache: about 1.3 GB per sequence at 4k context with grouped-query attention, and if weights leave only 20 GB free you fit fifteen sequences, not 256. So the serving stack is really a memory allocator — paged KV cache, quantization, continuous batching that evicts and admits every step. And the scheduler trades prefill against decode, which is TTFT against TPOT. Fleet is ~10,900 GPUs versus 0.27 web servers, so I'd evaluate every feature by whether it moves work off the GPU side."

Next: the building blocks, and the high-level flow.

Enjoying the preview?

Create a free account to unlock the rest of this course, the in-browser judge, and live AI mock interviews.

Sign up free to continue