0%
LLM Inference and Serving: GPUs, Batching, and Cost
Hardware and Memory
Making Inference Fast
Serving Systems
Latency Metrics: TTFT, TPOT and Throughput
LLM serving needs its own latency vocabulary, because a response is not a single event but a stream of tokens over seconds or minutes. A single number such as average request latency hides almost everything that matters to users and to capacity planning. This lesson defines the standard metrics, time to first token, time per output token, end to end latency and throughput, explains what drives each, shows how they trade against one another and how to measure and set targets for them. This first section covers time to first token.
Definition
Time to first token, TTFT, is the time from when the server receives a request to when it sends the first generated token. In a streaming API it is the delay before the user sees anything appear. For chat products, TTFT is the most visible latency: a response that begins in 300 milliseconds feels instant even if it takes ten seconds to finish, while one that sits blank for three seconds feels broken even if it then streams quickly. For agents and pipelines that do not stream, TTFT matters less on its own but still adds to every call in a chain.
TTFT can be measured at different points. Measured at the engine, it starts when the engine receives the request. Measured at the gateway, it includes routing, authentication and any queueing before the engine. Measured at the client, it includes the network round trip and TLS setup. Users experience the client side number; engineers debug with the engine side number. Dashboards should label which one they show, since the gap between them is often where problems hide.
What makes up TTFT
TTFT has four main components. Queueing delay is time spent waiting for the engine to admit the request, which is zero at low load and grows quickly as the server nears capacity. Prefill time is the time to process the prompt and produce the first token, which grows with prompt length. Scheduling interference is extra time when the prefill shares GPU steps with decode work for other sequences. And overheads include tokenization, request parsing, and the time to send the first token back through the stack.
At low load, prefill dominates. For an 8B model on an H100, prefill of a 1,000 token prompt takes about 30 to 50 milliseconds and of a 10,000 token prompt about 400 to 600 milliseconds. At high load, queueing dominates, and TTFT can rise from a fraction of a second to many seconds without any change in prompt length. This makes TTFT the metric most sensitive to load and therefore the most useful early warning that a deployment is running out of capacity.
Prompt length drives prefill
Prefill cost scales roughly linearly with prompt length for short and medium prompts and faster than linearly for very long prompts, because attention over n tokens costs n squared. Every token in the prompt counts: the system prompt, tool definitions, retrieved documents, conversation history and the current message. Teams are often surprised to learn that their real prompts are several thousand tokens long once all of this is included, and that the system prompt alone accounts for a large share of TTFT.
Prefix caching is the main tool against this. If the system prompt and tool definitions are identical across requests and come first, the engine reuses their cache and prefills only the new part. For multi turn conversations, the history up to the previous turn may already be cached on the replica that served it. A high prefix cache hit rate can cut TTFT by large factors for products with long shared prefixes, which is why prompt layout is a latency decision as well as a quality one.
Load drives queueing
As utilization approaches capacity, queueing delay grows sharply, as queueing theory predicts: the expected wait in a simple queue grows with utilization divided by one minus utilization, so going from 70 percent to 90 percent busy roughly quadruples the wait. In LLM serving the effect is amplified because capacity depends on the mix of requests: a burst of long prompts consumes prefill capacity and cache memory, and requests behind it wait. Keeping TTFT stable therefore requires headroom, admission control and autoscaling that reacts to queue depth, topics covered in lesson sixteen.
Interference with decode
In an engine that batches prefill and decode together, a large prefill in a step makes that step much longer, which delays every decoding sequence in the batch, while decode work in the step slightly delays the prefill. Engines manage this with chunked prefill, which splits long prompts into pieces processed over several steps, and some deployments separate prefill and decode onto different GPUs entirely. Both are covered in lesson thirteen. For TTFT, the relevant point is that the time to process your prompt depends partly on what else the server is doing at that moment.
TTFT for reasoning models
Reasoning models generate a long chain of thought before the visible answer. Whether the first token is counted from the first reasoning token or from the first answer token makes a large difference: the first reasoning token may arrive in half a second, while the first visible answer token may take thirty seconds or more. Products that hide reasoning should track time to first visible token separately, and capacity planning should count reasoning tokens as output tokens, since they occupy decode steps and cache just like visible ones.
Typical targets
Targets depend on the product. Interactive chat commonly aims for a TTFT under about one second at the 95th percentile, and many aim for 200 to 500 milliseconds at the median. Code completion in an editor needs much less, often under 200 milliseconds end to end for short completions, which constrains prompt length and model size. Batch document processing may tolerate many seconds or minutes. Voice assistants need low TTFT because speech synthesis cannot begin until text arrives, and every hundred milliseconds of delay is noticeable in conversation. Setting the target by product, not by habit, lets the rest of the serving configuration follow.
Measuring TTFT correctly
TTFT should be measured per request and reported as a distribution, at least the median, 95th and 99th percentiles, segmented by prompt length bucket, because a single average mixes short and long prompts that have very different expected values. Engines such as vLLM export a TTFT histogram as a Prometheus metric, and gateways can record it from the first streamed byte. Requests that fail or time out before the first token should be counted separately rather than dropped, since dropping them makes TTFT look better exactly when the system is worst.
Cold starts and TTFT
A request that lands on a replica that has just started can see a much higher TTFT than usual. A new replica must load weights, which for a 70B model can take a minute or more from local disk and longer from network storage, then capture CUDA graphs and warm up kernels for common shapes. Requests routed to it before warmup completes pay those costs. Health checks that report ready only after a warmup request has run, and routing that ramps traffic onto new replicas gradually, keep cold start latency out of user requests. Autoscaling decisions must account for this startup delay, since capacity added in response to a spike arrives minutes later.
Network and protocol overhead
Outside the engine, TTFT includes the TLS handshake for new connections, the round trip to the region hosting the model and any proxies in between. Reusing connections with HTTP keep alive or HTTP/2, placing gateways close to users and avoiding unnecessary hops can save 50 to 200 milliseconds, which is a large share of TTFT for short prompts on fast models.
Prefill time is stable for a given prompt length, so when TTFT rises without longer prompts, the extra time is queueing. Watching TTFT percentiles by prompt length bucket is the earliest signal that a deployment is near capacity.