Four GPU replicas serve 45 requests a second with a 4 ms average wait. At 50 a second the same four make the average request wait half a second. This engineer finds that cliff before the users do, and sizes the fleet so it never arrives.
Drag the traffic and pick a fleet size. Watch where the wait curve turns up. Then we build each skill, piece by piece: capacity, queues, GPU memory, decode speed, scheduling, training traffic, autoscaling and error budgets.
You need some Python and a rough idea of what a GPU and a language model are. We build the rest from zero.
A Day in the Life guide. Hardware and model numbers come from the vendor and model pages named in the Field Guide. Prices, traffic and timings are illustrative round numbers. The arithmetic is exact.
Pick how many GPU replicas serve the traffic.
Illustrative: each replica is one GPU with 64 batch slots, each request holds a slot for 5 s, a GPU-hour costs $3. Waits use the Erlang C formula for a pool of 64 × replicas slots. Chapters 1 and 2 rebuild every number.
Chapter 0
Follow one request onto a GPU and see which numbers this engineer controls
A user sends a 1,500-token question to a chat API. The first token comes back after 65 ms. The last of 500 tokens arrives about 4.7 s later. In between, the request shared a GPU with 63 others. For every token, the GPU read 31 GB of memory.
An infrastructure and LLM scaling engineer builds and runs the machines under the model. That means the GPU fleet, the scheduler, the serving layer, the autoscaler and the alarms. The job is to keep the service fast and up at the lowest cost. Each part has a number you can compute before you buy anything.
The bar is the life of one request. Change how many requests share the GPU, or make the pool nearly full.
Decode speeds are the memory-bandwidth ceiling for Llama 3.1 8B on one H100 (Chapter 4). Gateway and prefill times are illustrative. The queue wait comes from the hero at 50 req/s on 4 replicas.
A bigger batch makes each user's words come slower, from 142 to 72 per second. The GPU's total output still doubles from 4,540 to 9,270 tokens a second, so the cost per token halves. That trade between one user's speed and the fleet's cost runs through every chapter.
| Skill | The question it answers | Chapter |
|---|---|---|
| Capacity | How many requests are in flight, and how many replicas hold them? | 1 |
| Queues | How long do requests wait when the pool is 90% busy? | 2 |
| GPU memory | Do the weights and the KV cache fit? | 3 |
| Decode speed | How many tokens a second can one GPU make, at what cost? | 4 |
| Scheduling | Why does an 8-GPU job wait when 10 GPUs are free? | 5 |
| Training traffic | How long does it take to add up gradients across GPUs? | 6 |
| Autoscaling | How big a backlog builds while new GPUs start? | 7 |
| Reliability | How fast is the error budget burning, and when do you page? | 8 |
Failure: users report slow answers, but GPU use looks normal. Measure: split the time of each request into queue wait, prefill and decode, as in the bar. Fix: the wait is 500 ms because the pool runs at 98% busy. Add one replica (Chapter 2).
Chapter 1
Multiply the arrival rate by the time each request stays, and get the number of slots you must own
The product team expects 40 requests a second at the evening peak. Each request holds a batch slot on a GPU for about 5 seconds, from the first prompt token to the last answer token. How many slots must be free at once?
Little's law answers it for any stable system. Call the average number of requests inside the system L. Call the arrival rate, in requests per second, λ. Call the average time one request stays inside W.
L equals lambda times W.
Each second, lambda new requests come in. Each one stays W seconds. So at any moment, the requests of the last W seconds are all still inside: L of them.
With made-up numbers: lambda = 40 per second and W = 5 s give L = 200 requests in flight. With 64 slots per replica, 200 / 64 = 3.1, so you need at least 4 replicas.
Each box is a replica and each cell is a batch slot. Change the traffic, the time per request and the slots per replica.
Illustrative traffic. The minimum replica count is L divided by the slots per replica, rounded up. Chapter 2 shows why the minimum is not enough.
The law needs no assumption about how requests arrive. It holds for averages over any long window. That makes it the first line of every capacity plan. It also reads backwards: if a dashboard shows 300 requests in flight at 40 per second, each request stays 7.5 s, and something got slower.
Where does W come from? Measure it. Chapter 4 shows that 500 answer tokens at 108 tokens a second take 4.7 s. Round up to 5 s for slack. If answers grow to 1,000 tokens, W doubles, and so does L.
Failure: a new feature doubles answer length and the queue explodes with no rise in traffic. Measure: plot L and lambda side by side, then divide them to get W. Fix: plan capacity on tokens per request as well as requests per second.
Chapter 2
Use the Erlang C formula to see how the wait grows as a pool of servers gets busy
Four replicas give 256 slots, and Chapter 1 says 200 are in use on average. That leaves room on average. But requests arrive at random. Some seconds bring 50, some bring 30. In a busy second every slot is full. The next request waits in a queue, a line of requests with no slot yet.
Queueing theory predicts that wait. Model the pool as c identical servers. Requests arrive at random at rate λ, and each server finishes μ requests a second. The share of the pool in use is the busy share, λ / (cμ). Call a = λ / μ the average number of busy servers. The Erlang C formula, C(c, a), gives the chance that an arriving request finds all c servers busy.
W-q equals C of c and a, divided by c mu minus lambda.
The spare capacity, c times mu minus lambda, drains the queue. Divide the chance of waiting, C, by that spare capacity. Little spare capacity means a long wait.
With made-up numbers: c = 4 servers, mu = 10 per second, lambda = 32 per second, so a = 3.2 and the busy share is 80%. Erlang C gives C = 0.596. W-q = 0.596 / (40 − 32) = 0.0746 s, about 75 ms.
For that C, add the terms 1 + a + a²/2 + a³/6 = 1 + 3.2 + 5.12 + 5.461 = 14.781. The all-busy term is a4/24 × c/(c − a) = 4.369 × 5 = 21.845. Then C = 21.845 / (14.781 + 21.845) = 0.596. The code in the Field Guide does this for any c.
Each curve is a pool size. Every server finishes 10 requests a second. Drag the busy share and pick the pool.
Erlang C assumes random arrivals and random service times with the same average (the M/M/c queue). Real LLM requests vary more, so treat the curves as a lower bound on the wait.
At 90% busy, one server makes requests wait 900 ms. Sixteen servers at the same 90% make them wait 37 ms. Big pools absorb random bursts better. This is why one shared fleet beats many small private ones, and why the hero's 256-slot pool stays calm past 90% busy and then breaks.
Failure: a team runs each customer on its own 2-replica pool at 85% busy, and tail latency is awful. Measure: plot queue wait against busy share per pool. Fix: merge pools, or plan small pools for 60 to 70% busy.
Chapter 3
Add the weights to the KV cache of every running request and check it against GPU memory
A GPU holds two big things for serving. The weights are the model's parameters, fixed in size. The KV cache stores the attention keys and values of every token of every running request. With it, the model does not recompute them for the next token. The cache grows with each token.
How big is the cache for one token? Each layer stores one key and one value vector for each KV head. Call the number of layers nL and the KV heads per layer nkv. Call the size of each head d and the bytes per number s.
b equals two, times n-L, times n-k-v, times d, times s.
Multiply the layers, the KV heads and the head size. Double it, for one key and one value. Multiply by the bytes per number.
Llama 3.1 70B has 80 layers, 8 KV heads and heads of 128. In BF16: b = 2 × 80 × 8 × 128 × 2 = 327,680 bytes, about 0.33 MB per token. Llama 3.1 8B, with 32 layers, gives 131,072 bytes.
Now the budget. Call the total GPU memory M, the share a serving engine may use u, and the weight bytes w. What is left holds N tokens of cache.
N equals u times M, minus w, all over b.
Take the usable memory, u times M. Subtract the weights w. Divide what is left by the bytes per token b.
Llama 3.1 70B in BF16 is about 141 GB. On two 80 GB H100s: N = (0.9 × 160 − 141.2) GB / 327,680 B = about 8,500 tokens, room for four 1,800-token requests. On four: about 448,000 tokens.
The bar is all GPU memory for one replica. Pick a model and GPU count, then change the usable share and the request length.
Layer and head counts from the Llama 3.1 model configs; 80 GB per H100 from NVIDIA's H100 page. Weights at 8.03 B and 70.6 B parameters in BF16. Engine overheads vary.
Two GPUs hold the 70B weights but leave room for only four requests. That is a fleet that loads and then cannot serve. Four GPUs, split by tensor parallelism, leave room for about 250 requests of 1,800 tokens.
Failure: throughput collapses at peak and the engine logs many preemptions. Measure: watch KV cache use; near 100%, the engine evicts running requests and recomputes them. Fix: shorten the context limit, quantize the cache, or add GPUs per replica.
Chapter 4
Divide the bytes read per step by the memory bandwidth, and turn the result into tokens a second and dollars
To make one new token, the GPU runs one decode step. In each step it reads all the weights once, plus the KV cache of every request in the batch. The arithmetic is small next to the reading. So the speed limit is how fast memory delivers bytes, the memory bandwidth.
Call the step time t. The weights are w bytes. The batch has B requests, each with T tokens in cache, at b bytes per token. The bandwidth is BW bytes per second.
t equals w plus B times T times b, all over B-W.
Add the weight bytes to the cache bytes of the whole batch. Divide by the bandwidth. Each request gets one token per step, so the GPU makes B tokens every t seconds.
Take Llama 3.1 8B on one H100 with B = 64 and T = 1,800. Cache reads are 64 × 1,800 × 131,072 = 15.1 GB. t = (16.06 + 15.1) GB / 3,350 GB/s = 9.3 ms. Each user gets 108 tokens a second; the GPU makes 64 / 0.0093 = 6,881.
The rising line is the GPU's total output. The falling line is one user's speed. Drag the batch and the context length.
The bandwidth ceiling for Llama 3.1 8B in BF16 on one H100 SXM. Real engines reach part of it. Red marks batches whose cache does not fit in 72 GB. GPU-hour at an illustrative $3.
Price follows. One GPU-hour costs p dollars and makes 3,600 × R tokens, where R is total tokens a second. So a million tokens cost p × 1,000,000 / (3,600 × R).
Batching is the biggest cost lever in serving. It costs each user speed, so the batch size is a product decision as well as a cost one.
Failure: the bill doubles after a change that capped the batch at 16. Measure: log the running batch size and tokens a second per GPU. Fix: raise the cap until the per-user speed target binds.
Chapter 5
Place jobs on nodes so that large jobs still find a whole node
A cluster has 4 nodes, each a server with 8 GPUs joined by fast NVLink. Serving replicas ask for 1 to 3 GPUs. Training jobs ask for 2, 4 or 8. An 8-GPU job must sit on one node, because its GPUs talk to each other at every step and the links between nodes are slower.
The scheduler decides which node gets each job. Kubernetes and SLURM are two common ones. A rule that looks fair, "put each job on the emptiest node", spreads load evenly. It also chops free space into pieces too small for big jobs. That waste is fragmentation.
Ten jobs arrive in order. The last asks for a whole node. Pick a rule and run the queue.
Illustrative queue: serving 2, training 4, serving 1, serving 3, training 2, serving 2, training 4, serving 1, serving 3, then training 8. Spread picks the node with the most free GPUs; pack picks the node with the fewest that still fit.
Under spread, the first nine jobs use 22 GPUs and leave 10 free: 1, 4, 1 and 4 per node. No node has 8, so the training job waits. Under pack, the same nine jobs fill three nodes almost full and leave node 4 empty. The 8-GPU job starts at once.
| Rule | Good at | Bad at |
|---|---|---|
| Spread | Even heat and load, small blast radius when a node dies | Leaves no whole node for big jobs |
| Pack | Keeps whole nodes free for 8-GPU jobs | One node failure hits many jobs |
| Priority with preemption | Serving takes GPUs from training at peak | Training must checkpoint often or lose work |
Real clusters mix rules: pack training, spread serving replicas across nodes for safety, and give serving a higher priority. A training job that serving may interrupt saves a checkpoint, a copy of its state, every few minutes.
Failure: 8-GPU jobs sit pending for hours while the dashboard shows 30% of GPUs free. Measure: count free GPUs per node, not in total. Fix: pack small jobs, or reserve whole nodes for large ones.
Chapter 6
Compute how long a ring all-reduce takes, inside one node and across many
In data-parallel training, every GPU holds a copy of the model and trains on its own slice of the batch. After each step, every GPU has its own gradients. The GPUs must average them so all copies stay the same. That averaging is an all-reduce.
A ring all-reduce arranges the GPUs in a circle. Each GPU splits its gradients into N chunks and passes them to its neighbour, adding as it goes. After N − 1 passes each GPU holds one fully summed chunk. N − 1 more passes share the sums. Call the gradient size S bytes, the GPU count N, and the bandwidth of the slowest link in the ring BW.
t equals two times N minus one over N, times S over B-W.
Each GPU sends almost twice its gradient size, S, over its link: once to sum and once to share. Divide by the slowest link's bandwidth. The factor (N − 1) / N stays near 1, so adding GPUs barely changes t.
Llama 3.1 8B gradients in BF16: S = 16.06 GB. Take eight GPUs on NVLink at 450 GB/s each way. Then t = 2 × 7/8 × 16.06 / 450 = 62.5 ms. For 32 GPUs on 4 nodes with 50 GB/s network links, t = 2 × 31/32 × 16.06 / 50 = 0.62 s.
Chunks travel round the ring. Change the GPU count and the model. Past 8 GPUs the ring leaves the node and the network sets the pace.
H100 NVLink is 900 GB/s total per NVIDIA, so 450 GB/s each way. The 50 GB/s network link (a 400 Gb/s card per GPU) and the 1 s compute step are illustrative. Real libraries such as NCCL also use trees and overlap traffic with compute.
The ring is bandwidth-optimal, but it runs at the speed of its slowest link. Inside a node that is NVLink. Across nodes it is the network card, nine times slower here. For a 70B model the same formula gives 5.5 s per step across 32 GPUs, longer than the compute.
There are three fixes. Overlap the all-reduce with the backward pass. Shard the model (FSDP) so each GPU sends less. Keep the heaviest traffic inside nodes.
Failure: going from 8 to 32 GPUs gives only 1.6 times the speed. Measure: profile one step and split it into compute and communication. Fix: overlap, shard, or buy faster links between nodes.
Chapter 7
Use the autoscaler's ratio rule, then count the backlog that builds while new GPUs start
Traffic jumps from 40 to 60 requests a second at 7 p.m. An autoscaler adds replicas when load rises and removes them when it falls. The Kubernetes Horizontal Pod Autoscaler uses one ratio. Call the current replica count n, the metric you watch per replica m, and your target for it m*.
n-prime equals the ceiling of n times m over m-star.
Divide the current metric m by the target m-star. Scale the replica count n by that ratio and round up. If the ratio is within 10% of 1, the autoscaler does nothing.
With made-up numbers: 4 replicas, demand 60 × 5 = 300 in flight, so m = 75 per replica. With m-star = 60: n-prime = ceiling of 4 × 75 / 60 = 5.
The fifth replica is not ready at once. A new GPU node must boot, pull a large container image and load the weights. Call that cold start time Tc. Four replicas finish 4 × 64 / 5 = 51.2 requests a second. The extra 8.8 a second pile up.
Traffic steps from 40 to 60 a second at minute 2. Change the target per replica and the cold start time, then watch the backlog.
Illustrative: 64 slots per replica, 5 s per request, the autoscaler checks every 15 s, an illustrative $3 per GPU-hour. The ratio rule and the 10% tolerance follow the Kubernetes HPA documentation.
Set m-star to 48 and the fleet starts with 5 replicas, enough for 64 requests a second. The step passes with no backlog, for one extra GPU at $3 an hour. Headroom buys time for the cold start. Shorter cold starts, from cached images and preloaded weights, buy the same thing.
Failure: the fleet flaps, adding and removing replicas every minute. Measure: plot replica count against the metric. Fix: scale down slowly; the HPA's default waits 300 s before it scales down.
Chapter 8
Turn a reliability target into a budget of failures, and page on how fast you spend it
"The API should be reliable" is not a number. A service level indicator (SLI) is a measured ratio, such as good requests over all requests. A service level objective (SLO) is the target for it, such as 99.9% over 30 days. The error budget is what the SLO allows to fail: 0.1% of requests.
At 10 million requests a month, the budget is 10,000 failed requests, or 43.2 minutes of full outage. Teams spend it on risky releases. When it runs out, they slow releases and fix reliability.
When should a person get paged? Call the current error rate e and the SLO S. The burn rate r says how many times faster than allowed you spend the budget.
r equals e over one minus S.
Divide the error rate you see, e, by the error rate the SLO allows, one minus S. The result r tells you how fast the budget goes. At rate r, the whole budget lasts 30 days divided by r.
An error rate e = 1.44% against S = 99.9% gives r = 0.0144 / 0.001 = 14.4. One hour at that rate spends 14.4 / 720 = 2% of a 30-day budget. The whole budget lasts 720 / 14.4 = 50 hours.
The line is the budget left over 30 days. An incident starts on day 10. Change how bad it is and how long it lasts.
Illustrative 0.02% background error rate. The page rule, a burn rate of 14.4 sustained for one hour, is the Google SRE Workbook's example for a 99.9% SLO. The workbook pairs it with a short window so the alert also clears fast.
A burn-rate alert pages on what matters: the budget. A blip to 2% errors for one minute has burn rate 20 but spends 0.05% of the budget, so it should not wake anyone. A steady 0.5% error rate never trips a 5% threshold, yet at burn rate 5 it empties the budget in 6 days.
Failure: on-call gets 50 pages a day and starts ignoring them. Measure: count pages per week and the budget each one spent. Fix: page only on fast burns, and send slow burns to a ticket.
Chapter 9
Keep the terms, the numbers, the checklist and the code in one place
An infrastructure and LLM scaling engineer turns traffic forecasts into a fleet with a known wait, a known cost and a known failure budget. Each skill on this page is one number you can compute and one failure you can catch.
| Term | What it is | Worked number here |
|---|---|---|
| Little's law | In flight = arrival rate × time in system | 40 /s × 5 s = 200, so 4 replicas of 64 slots |
| Erlang C wait | C(c, a) / (cμ − λ) | 4 servers at 80%: 75 ms; 1 server at 80%: 400 ms |
| KV bytes per token | 2 × layers × KV heads × head size × bytes | Llama 3.1 70B: 327,680; 8B: 131,072 |
| Cache room | (u × M − weights) / bytes per token | 70B on 2 H100s: 8,500 tokens; on 4: 448,000 |
| Decode step | (weights + batch cache bytes) / bandwidth | 8B, batch 64: 9.3 ms, 6,881 tokens/s |
| Cost per million tokens | $ per GPU-hour × 106 / (3,600 × tokens/s) | $0.121 at batch 64, $4.05 at batch 1 |
| Ring all-reduce | 2(N − 1)/N × size / slowest link | 16 GB: 62.5 ms in a node, 0.62 s on 4 nodes |
| Autoscaler | ceil(n × metric / target) | ceil(4 × 75 / 60) = 5 |
| Cold-start backlog | (traffic − capacity) × cold start | 8.8 × 180 = 1,584 requests |
| Burn rate | error rate / (1 − SLO) | 1.44% at 99.9%: 14.4, 2% of budget an hour |
| Fact | Value | Source |
|---|---|---|
| H100 SXM memory | 80 GB HBM3 | NVIDIA H100 page |
| H100 SXM memory bandwidth | 3.35 TB/s | NVIDIA H100 page |
| H100 NVLink | 900 GB/s total | NVIDIA H100 page |
| Llama 3.1 8B | 32 layers, 8 KV heads, head size 128 | Model config on Hugging Face |
| Llama 3.1 70B | 80 layers, 8 KV heads, head size 128 | Model config on Hugging Face |
pythonimport math def erlang_c(c, a): # chance all c servers are busy; a = lam / mu if a >= c: return 1.0 B = 1.0 # Erlang B, built up one server at a time for k in range(1, c + 1): B = a * B / (k + a * B) return B / (1 - (a / c) * (1 - B)) def mean_wait(c, lam, mu): # seconds in the queue a = lam / mu return math.inf if a >= c else erlang_c(c, a) / (c * mu - lam) def kv_bytes(layers, kv_heads, head, s=2): return 2 * layers * kv_heads * head * s def step_time(w, B, T, b, bw): return (w + B * T * b) / bw def ring_allreduce(N, S, bw): return 2 * (N - 1) / N * S / bw def burn_rate(err, slo): return err / (1 - slo) print(mean_wait(4, 32, 10)) # 0.0746 s print(mean_wait(256, 50, 0.2)) # 0.506 s: the hero at 50 req/s, 4 replicas b = kv_bytes(32, 8, 128) # 131,072 for Llama 3.1 8B t = step_time(16.06e9, 64, 1800, b, 3.35e12) # 0.0093 s print(64 / t, ring_allreduce(8, 16.06e9, 450e9), burn_rate(0.0144, 0.999))
Now press Present or Teach. Explain from memory: Little's law, why small pools wait longer, the KV cache budget, the decode step time, fragmentation, the ring all-reduce, the cold-start backlog and the burn rate. Then go back to the hero and say why the curve for 4 replicas turns up near 50 requests a second.