Katkat

Streaming and Latency Metrics: TTFT and Tokens per Second

By the Katkat team · Updated · 9 min read

Quick overview

Learn what TTFT, inter-token latency and tokens per second measure, where LLM latency comes from, and how streaming changes perceived speed.

Lesson 15 of 88 · AI Engineering Interview Course

After this lesson you will be able to define time to first token (TTFT), inter-token latency and tokens per second, and say which part of a request each one reflects. You will be able to break a slow LLM response into network, queueing, prefill and decode time, and explain why streaming improves perceived speed without making generation faster. You will also know the practical traps that streaming introduces.

Why one latency number is not enough

A chat request is not one unit of work. The model first reads the whole prompt, then produces the answer one token at a time. These two phases have different costs and different bottlenecks, so a single "response time" hides what is going on.

The metrics used in practice:

MetricWhat it measuresMostly driven by
TTFT (time to first token)Request sent until the first output token arrivesNetwork, queueing, prompt length (prefill)
ITL (inter-token latency)Gap between consecutive output tokens. Also called time per output token (TPOT)Decode speed, batch size, KV cache reads
Tokens per second (per user)Roughly 1 / ITL for one streamSame as ITL
End-to-end latencyRequest sent until the last token arrivesTTFT + (N − 1) × ITL for N output tokens
Throughput (system)Total tokens per second across all usersBatching, hardware, scheduling

Per-user tokens per second and system throughput are different things. A server can have excellent throughput while each individual user sees a slow stream. Always ask which one is meant.

Where the time goes

Follow one request from the client to the last token:

  1. Client to server network. Connection setup, TLS, and the round trip. Often tens of milliseconds, more across regions.
  2. Your own application work. Retrieval, prompt assembly, auth, guardrail checks that run before the model call. In a RAG app this can rival the model time.
  3. Queueing. The request waits for a free slot on the inference server. Under load this grows quickly, and it is a common cause of bad tail latency.
  4. Prefill. The model processes all prompt tokens in parallel and builds the KV cache. Cost grows with prompt length. See Prefill, Decode and the KV Cache.
  5. Decode. One token per step, each step depending on the last. Cost grows with output length.
  6. Post-processing. Output validation, parsing, moderation, and logging, if they must finish before the user sees anything.

TTFT is steps 1 to 4 plus the first decode step. Everything after that is a stream of decode steps, so output length times ITL dominates total time for long answers.

Time to first token

TTFT is the metric for "does the app feel responsive". Its main components are network, queueing and prefill.

Prefill is compute-bound. The GPU does large matrix multiplications over all prompt tokens at once, so prefill time scales roughly linearly with prompt length (attention adds a term that grows faster for very long prompts). Doubling the prompt roughly doubles the prefill cost.

Ways to lower TTFT:

  • Shorten the prompt: trim retrieved context, drop stale chat history, tighten the system prompt. See Context Windows.
  • Reuse work with prefix caching, so a shared system prompt or document is not recomputed on every request. See Prefix Caching.
  • Reduce queueing by adding capacity or limiting admission.
  • Run pre-model steps (retrieval, guardrail checks) in parallel where they do not depend on each other.
  • Use a smaller or faster model for the first response, if quality allows.

Inter-token latency and tokens per second

Decode generates one token per step, and each step must read the model weights from GPU memory plus the KV cache for the sequence. At small batch sizes this is memory-bandwidth-bound, not compute-bound. That is why decode speed depends so much on memory bandwidth and model size in bytes.

A rough upper bound for one stream at batch size 1 is memory bandwidth divided by bytes read per token. As an approximate illustration, take an 8B-parameter model in 16-bit weights, which is about 16 GB. On a GPU with roughly 3 TB/s of memory bandwidth (a figure that varies by hardware):

  • 16 GB / 3,000 GB/s ≈ 5.3 ms per token
  • 1 / 0.0053 s ≈ 190 tokens per second, as a ceiling

Real systems come in lower because of KV cache reads, kernel overheads and scheduling. The point is the shape of the calculation: halving the bytes per weight (quantization, see Quantization) roughly halves the weight-reading time.

Batching changes the trade-off. Serving many users together reuses each weight read across all of them, so system throughput rises a lot. Each user's ITL usually rises somewhat as the batch grows, since each step does more work and reads more KV cache. This is the central latency versus throughput tension in serving. See Continuous Batching.

A worked example

Suppose a request has a 3,000-token prompt and produces 400 output tokens. Assume these approximate numbers:

  • Network round trip: 80 ms
  • Queue wait: 50 ms
  • Prefill speed: 10,000 prompt tokens per second
  • Decode speed: 40 tokens per second, so ITL = 1000 / 40 = 25 ms

Compute each part:

  • Prefill = 3,000 / 10,000 = 0.3 s = 300 ms
  • TTFT ≈ 80 + 50 + 300 = 430 ms
  • Remaining tokens = 400 − 1 = 399, so decode time ≈ 399 × 25 ms = 9,975 ms
  • End-to-end ≈ 430 + 9,975 = 10,405 ms ≈ 10.4 s

Without streaming the user stares at a blank screen for about 10.4 s. With streaming they see text after about 0.43 s and then watch it arrive.

Now compare two changes:

ChangeNew TTFTNew end-to-end
Prompt grows to 12,000 tokens (prefill = 1,200 ms)80 + 50 + 1,200 = 1,330 ms1,330 + 9,975 = 11,305 ms
Output capped to 200 tokens (decode = 199 × 25 = 4,975 ms)430 ms430 + 4,975 = 5,405 ms

Longer prompts hurt TTFT. Longer outputs hurt total time. Capping output length, or asking for a concise answer, often saves more total time than any infrastructure tweak. The example ignores the small slowdown in decode as the KV cache grows.

Streaming: mechanism and UX

Streaming means the server sends tokens to the client as they are generated, instead of waiting for the full response. Over HTTP this is commonly done with server-sent events (a long-lived response with incremental data: messages) or with WebSockets when you need two-way traffic.

Streaming does not reduce end-to-end latency. In the example above the last token still arrives at about 10.4 s. What changes is perceived latency: the user starts reading at TTFT and reads while generation continues. If the stream is faster than reading speed (a person reads somewhere around 5 to 10 tokens per second), the user is never waiting after the first token, so TTFT matters most for feel.

UX points worth knowing:

  • Show activity immediately (a typing indicator) before the first token, since TTFT is never zero.
  • Smooth the output. Tokens arrive in uneven bursts because of network buffering and batching, so many UIs render at a steady pace.
  • Let the user stop generation. Cancelling should also abort the server-side job so the GPU does not keep decoding for a closed tab.
  • Render partial Markdown carefully, because half-finished code fences and lists flicker.

Trade-offs and pitfalls of streaming

Streaming moves complexity into your application:

  • Validation after the fact. You cannot validate a complete JSON object or run an output safety check before showing text that is already on screen. Options are to stream only the user-facing text, buffer until a check passes, or accept partial display with a retraction path. See Getting Reliable JSON and Structured Output.
  • Errors mid-stream. The HTTP status was already sent as success when the first byte went out. Failures must be signalled inside the stream, and the client must handle truncated output.
  • Proxy buffering. Load balancers, CDNs and reverse proxies may buffer responses and defeat streaming unless configured to pass them through.
  • Tool calls. Tool-call arguments also arrive incrementally. Wait for a complete call before executing it.
  • Usage accounting. Token counts for billing and rate limiting are often only known at the end, so design logging around that.

Other latency levers, each with a cost: speculative decoding can raise tokens per second (and makes token arrival bursty, see Speculative Decoding); smaller models cut both prefill and decode time but may hurt quality; and routing simple queries to a fast model reduces average latency.

Measuring it properly

Instrument TTFT and ITL separately, on both the server and the client, because network and buffering only show up on the client. Record them per request along with prompt tokens and output tokens, so you can tell "slow because long" from "slow because overloaded".

Report percentiles, not averages. A p50 TTFT of 400 ms with a p99 of 6 s means one user in a hundred has a bad experience, usually due to queueing or a very long prompt. Set separate targets: for example a TTFT target for interactivity and a tokens-per-second target for stream smoothness. Tracing every stage of a request makes it clear which stage to fix. See LLM Observability and Tracing and How Would You Cut LLM Response Latency in Half?.

How does this come up in interviews?

1. What is TTFT and what affects it? TTFT is the time from sending a request to receiving the first output token. It is made of network time, queueing, and prefill, and prefill grows with prompt length. To reduce it, shorten prompts, use prefix caching, cut queue time, and parallelize pre-model work.

2. Streaming does not make the model faster, so why use it? It does not change end-to-end time, but it moves the first visible output to TTFT instead of the full completion time. Users can start reading while decoding continues, so the app feels much faster. The cost is harder validation, mid-stream error handling, and cancellation logic.

3. A user reports the stream is slow once text starts but the first token was quick. What do you check? That points at decode, so look at ITL: batch size and load on the server, KV cache pressure from long contexts, model size and precision, and client or proxy buffering. Compare server-side ITL with client-side arrival times to separate model slowness from network or buffering.

4. How does batching affect latency and throughput? Larger batches reuse each weight read across more requests, so system throughput rises. Per-user ITL tends to rise too, and queueing can grow if capacity is tight. You choose a batch and capacity target that meets your TTFT and ITL goals, not the highest possible throughput.

5. How would you estimate total response time for a request? Use TTFT plus (output tokens − 1) times ITL. Estimate TTFT from network, queue and prompt tokens divided by prefill speed, and ITL as 1 over per-user tokens per second. State the assumptions and that real numbers depend on hardware and load.

Common mistakes

  • Reporting a single "latency" number instead of TTFT, ITL and end-to-end separately.
  • Confusing system throughput with per-user tokens per second.
  • Using averages and ignoring p95 and p99, where queueing problems show up.
  • Claiming streaming reduces total generation time.
  • Forgetting that output length drives total time, and not capping or guiding it.
  • Measuring only on the server and missing buffering in proxies and clients.
  • Not cancelling generation when the client disconnects, which wastes GPU capacity.
  • Trying to validate full structured output before it is complete, or executing tool calls from partial arguments.
  • Treating hardware-dependent figures (bandwidth, tokens per second) as universal constants.