What they’re really asking
If you only remember one thing, say this in the first minute: “About 40,000 replies are being written at any moment, and GPU memory decides how many fit on one machine: about 350, or 699 if all users share one cached copy of the system prompt. So sharing that prompt halves the fleet, from 115 machines to 58. I’ll keep two latency budgets, one for the first word and one for the gap between words, and read long prompts in slices so they don’t stall everyone else. Free users are limited by tokens, a disconnect gets a short grace window before we cancel, and in a spike the free tier degrades first.”
The rest of this page explains each part of that answer.
The interviewer is asking: can you run a scarce, memory-bound resource for millions of impatient users, and say what each user sees when it runs out?
What makes this different from a normal web service
A normal request takes milliseconds, holds nothing afterwards, and costs about the same as any other. A chat reply from a large language model (LLM) breaks all three:
- It runs for many seconds. The model writes the reply in pieces of about ¾ of a word, called tokens, one at a time. A 400-token reply takes about 20 seconds, so it is streamed as it is written.
- It holds GPU memory the whole time. That memory, not GPU speed, limits how many users one machine serves.
- Costs differ by orders of magnitude. A 100-token question and a 100,000-token pasted document are both “one request”.
The question was reported as the title of an OpenAI software-engineer onsite item that names streaming, free-tier limits and GPU scheduling (PracHub). The round is decided in the follow-ups the site’s write-up lists: two latency budgets, a disconnect mid-reply, a shared system prompt, a rollout, and who degrades first. Only the title is candidate-reported.
Clarify first
All of these are assumptions. Say them out loud, and design inside the interviewer’s numbers if they differ.
- Which team? “I’ll assume an inference team, so GPU scheduling is in scope.”
- Peak load? “2,000 new messages (“turns”) per second.”
- Latency targets? “First word under 1 s at p95 for paid and 2 s for free; under 50 ms between words.”
- Model and hardware? “Llama-3.1-70B, an open model whose sizes are published, stored at 2 bytes per number (bf16), on machines of 8 H100 GPUs. The model is split across all 8 so they act as one; that is called tensor parallelism, written TP=8.”
- Conversation shape? “A 2,000-token system prompt shared by every user, 1,500 tokens of history, a 100-token message and a 400-token reply.”
Answer
Words you need first
- Prefill: the model reads the whole prompt in one big pass before writing. It sets the wait for the first word, called time to first token (TTFT).
- Decode: the model writes one token per pass, and each pass serves every user on the machine. It sets the gap between words, called inter-token latency (ITL).
- KV cache: the saved summary of every token so far that decode keeps in GPU memory, so it doesn’t re-read the conversation. It is what fills the machine.
Step 1: how many replies are open
Each reply stays open about 20 seconds. At 2,000 new messages a second, about 40,000 replies are open at any moment. This rule (open items = arrival rate × time each stays) is Little’s law.
Step 2: how many fit on one machine
For this model each token in a conversation costs 327,680 bytes of KV cache. Our example conversation holds 4,000 tokens by the end of its reply, so about 1.31 GB for the whole time it streams.
An 8-GPU machine has 640 GB of GPU memory. The model’s weights take 141.1 GB, and we assume 5 GB per GPU of working space. That leaves about 459 GB for KV caches: 350 conversations. If the 2,000-token system prompt is stored once and shared, each conversation needs only its own 2,000 tokens: 699 conversations.
So 40,000 open replies need 115 machines without sharing, 58 with it.
Say it like this: “Sharing one system prompt halves the fleet. That’s the cost case for the shared-prompt follow-up.”
The arithmetic behind the numbers (for a Staff-level follow-up)
- Open replies: 400 tokens × 50 ms = 20 s. 2,000 turns/s × 20 s = 40,000.
- KV per token: 2 × layers × KV heads × head size × bytes = 2 × 80 × 8 × 128 × 2 = 327,680 B. The model has 64 query heads but only 8 KV heads; using 64, or the hidden size, makes the cache 8× too big.
- One stream: 4,000 × 327,680 B = 1.31 GB.
- Streams per machine: (GPUs × memory − weights − GPUs × overhead) ÷ KV per stream. With 80 GB per H100 SXM, 141.1 GB of bf16 weights (exact config basis) and 5 GB per GPU of overhead (assumed): (640 − 141.1 − 40) ÷ 1.311 = 350. With the system prompt shared: 699.
- Fleet: 40,000 ÷ 350 = 115; 40,000 ÷ 699 = 58.
Step 3: the design
Client
│ POST message ▲ SSE events, offset in each id
▼ │
API gateway ── login, tier, one stream per free user, reserve tokens
▼ │
Conversation service ── history + system prompt + message
▼ │
Router ── same machine as last turn, free KV memory, queue depth
▼ │
GPU machine ── per-tier queues, many users per pass, │
shared prefix cache, prefill in slices ──► Stream gateway
▲ (replay buffer, heartbeats)
└──────────── cancel ─────────────────┘
The API gateway checks the user, enforces one open stream per free user and reserves tokens. The conversation service builds the prompt. The router prefers the machine that served the conversation’s last turn, because its KV cache may still be there; this is called affinity. The GPU machine queues by tier, decodes all admitted users together in each pass (continuous batching), keeps the system prompt’s KV once (prefix cache), and reads new prompts in slices. The stream gateway sends each token as a Server-Sent Event (a long-lived HTTP response) whose id holds the token offset, so a reconnect can resume.
Step 4: the two budgets, with numbers
The first-word wait is spent in the queue and in prefill. For our 3,600-token prompt the hardware can’t prefill faster than about 64 ms, or 28.5 ms if the system prompt is cached. So when TTFT is bad, look at queueing and very long prompts first.
The word gap is spent in decode. At 699 users each pass takes at least about 37.7 ms, because every pass reads the weights and every user’s KV cache from memory. That fits the 50 ms budget.
Prefill steals from the word gap. A new prompt read inside a decode pass makes that pass longer for all 699 users. So cap how much prefill runs per pass: the 12 or so milliseconds left in the budget allow about 688 tokens per pass. This is chunked prefill.
One more point for Staff level: the real limit per machine is the smaller of the memory limit (699) and the word-gap limit. The word-gap limit depends on how close real code gets to the hardware’s peak memory speed, so only a measurement tells you which one binds.
The arithmetic behind the numbers (for a Staff-level follow-up)
- Prefill floor: 2 × 70.55 × 10⁹ × 3,600 ÷ 7.916 × 10¹⁵ FLOP/s (8 GPUs × 989.5 TFLOPS dense bf16) = 64 ms. With 1,600 uncached tokens: 28.5 ms.
- Decode pass at 699 users: (17.64 GB weights per GPU + 699 × 3,800 tokens × 40,960 B per GPU) ÷ 3.35 TB/s = 37.7 ms. Each GPU holds one-eighth of the weights (141.1 ÷ 8) and one of the 8 KV heads (327,680 ÷ 8 = 40,960 B per token); 3,800 is the average context while the reply is written (3,600 + 400 ÷ 2).
- Slice size: (50 − 37.7) ms × 7.916 × 10¹⁵ ÷ (2 × 70.55 × 10⁹) ≈ 688 tokens.
Step 5: disconnects and spikes
Back to our user. At token 200 their phone loses signal. Heartbeats show the connection is dead. A short grace
window keeps the reply generating into a buffer. If the phone reconnects and sends the last event id it saw, in
the Last-Event-ID header, the gateway replays from token 201. If not, a cancel frees the KV memory.
In a spike: protect replies already running, shed background and free traffic first, let paid users’ word gap stretch, and reject paid requests last.
Senior vs Staff
ChatGPT-style serving
Senior
- Separates TTFT and ITL with numbers, sizes KV with KV heads, and handles disconnects with resume and cancel.
Staff
- Shows the per-node limit is min(KV cap, ITL cap), turns prefix sharing into fleet size, and writes the degradation ladder with a metric per step before the spike.
Small-team version
If you call a provider instead of running GPUs, keep the product half: an SSE relay through your backend that closes the upstream call when the user disconnects, per-user and per-plan token quotas with reserve-and-refund, and fallback to a second model only before the first token.
A feature with 50,000 requests a day has only about 21 open streams at peak. Connections aren’t the limit. The provider’s monthly spend cap is: at Claude Sonnet 5 list prices (fetched 2026-10-11) the feature costs about $0.0064 a request with a 2,000-token cached prefix, about $9,600 per 30 days, against tier caps of $500 or $1,000. Self-host only at hundreds of millions of steady output tokens a month.
The arithmetic behind the numbers (for a Staff-level follow-up)
- 50,000 ÷ 86,400 s = 0.58 requests/s; at an assumed 4× peak, 2.3/s. Each stream lasts about 9 s, so 2.3 × 9 ≈ 21 open.
- Per request: 1,000 × $2/M + 2,000 × $0.20/M + 400 × $10/M = $0.0064. × 50,000 × 30 = $9,600.
- See the family walkthrough’s small-team section for the full sizing.
Pitfalls
- One latency number. The first-word wait and the word gap have different causes and different fixes.
- The KV formula with hidden size. It is 8× too high for this model, which has 8 KV heads, not 64.
- Request-count limits. Prompts differ by three orders of magnitude, so count tokens.
- Dropping tokens for slow readers. Group several tokens into one event instead; a reply can’t have holes.
- Autoscaling on GPU utilization. A busy GPU and a drowning one look the same; scale on queue depth or TTFT.
Go deeper
- Family walkthrough: Serve a ChatGPT-style assistant with streaming, especially its back-of-envelope and deep dives.
- The limiter behind the free tier: rate limits, credits and admission control.
- The scheduler as code: continuous batching.
- Labs: Build Your Own WebSocket Pub/Sub Gateway for resume, Build Your Own Distributed Rate Limiter for tiers, Build Your Own LLM Inference EnginePartial for the engine.