esc
  • WorkflowsPages
  • Case studiesPages
  • Machine Learning FoundationsLearn
  • AI EngineeringLearn
  • AI Guardrails & Red TeamingLearn
  • UI/UXLearn
  • Design SystemsLearn
  • Production System DesignLearn
  • AI papersPages
  • Interview KitPages
  • Book a callContact
  • Download ResumeContact
Let’s talk

I’ll build the agent for it.

How Do You Diagnose a Slow LLM Pipeline?

How to find where an LLM pipeline loses time, which numbers to measure and the usual fixes, explained simply for your AI interview.

In short

Measure before you change anything. Time every step from the user's click to the last word on screen, compare time to first token with total time, and find the step that holds most of the wait. Then fix that cause first.

13 min readIntermediateVery common · estimateFacts checked 26 November 2026

Say it out loud

Read it once, then say it without looking. Start with the short one; use the long one when they ask you to go deeper.

When an AI pipeline is slow, I don't guess. I time every step, from the user's click to the last word on screen. I look at time to first token and total time, at the median and the 95th percentile, and at the token counts for each call. Then I find the slow step. Usually it's too many calls one after another, a long prompt with no cache, or an answer much longer than the user needs. I fix that step first, then measure again.

What is a slow LLM pipeline, in plain words?

An LLM pipeline is a chain of steps that ends in a model's answer. It might rewrite the user's question, search your documents, call the model, then check the reply before showing it. Every step takes time, and the pipeline feels slow when the user waits too long for the whole chain.

Diagnosing it means finding which step makes them wait. Think of a bank branch manager timing a customer's visit. Nobody cares that the teller is quick if the form goes to three desks first. The manager times the whole visit, then finds the desk where people stand.

Take a card-fee assistant at a mid-size bank. Its answers take about 8 to 10 seconds, and the team's first guess is that the model is too slow. That is only a guess. The timings will show the real cause.

Key words

Token
A small piece of text, often part of a word, that the model reads and writes. Speed and cost both count tokens.
Median
The middle run when you line up every run by time. Half are faster, half slower.
Time to first token (TTFT)
How long, from sending the model request until the first word of the reply arrives.
End-to-end latency
How long the user waits, from their click to the full answer on screen.
95th percentile (p95)
The time that 95 out of 100 runs finish within. The slowest 1 in 20 take longer than this.

Which numbers should you measure?

Start with the two timings for the whole request. OpenAI's latency guide says to measure where users wait before you change the model or the prompt, and it defines time to first token and end-to-end latency.

  • “Measure where users wait before changing the model or prompt.”

    OpenAI, latency optimization

  • “Time to first token (TTFT) measures how long an API request takes to start returning content.”

    OpenAI, latency optimization

  • Time to first token

    When the first word appears

    Hit hard by a long prompt. Work done before the model call is not in this number, so time it separately.

  • Total time

    When the answer is complete

    Adds every lookup, model call, tool call and retry before the last word.

  • Token counts

    How much went in and out

    Input, cached input and output tokens, recorded next to each timing.

Then compare the median with the 95th percentile. The median is the typical run. The 95th percentile shows how bad the slow runs get, and OpenAI says to compare both on representative traffic.

The vLLM project's metrics page names the same measures. Its time per output token is the average gap between output tokens once the answer has started. It is worked out from the end-to-end time minus the first-token time, divided by the number of output tokens after the first.

Where does the time go?

Find the slow step before you touch the prompt. The chart shows the path from the question to the fix, with the usual causes listed after the timed steps.

Finding the slow step

Question sent

the timer starts here

Each step is timed

Rewrite the question

a model call, and it goes first

Search the policy files

a tool, not the model

Write the answer

often the longest step

Check the reply

often a second model call

Compare with usual causes

Calls one after another

each call adds its wait

Long, uncached prompt

delays the first token

Answer too long

more tokens to write

Fix one, measure again

keep it only if numbers move

  1. 1The timer starts when the user sends the question and runs through every step.
  2. 2The slowest step is matched to the usual cause that fits it.
  3. 3One fix goes in, then the pipeline is timed again.
The timer starts when the user sends the question and runs through every step. The slowest step is matched to a likely cause, then one fix goes in and the pipeline is timed again. Nothing changes before the timings say where to look.
  1. 1

    Time the whole visit

    From the user's click to the last word on screen, including the browser's drawing of the reply.

  2. 2

    Time each step

    Retrieval, every model call, every tool call and the final check, each on its own clock.

  3. 3

    Read the slowest step

    Usually one step holds most of the wait. A median can hide a stall that only some runs hit.

  4. 4

    Check the token counts

    Long input mostly delays the first word. Long output adds time at the end.

Here is the idea in Python, with five made-up slow runs from that assistant. The answer step takes most of the wait, and one search stalled once.

Python
# Made-up timings in milliseconds for five slow answers from a bank's card-fee assistant.
import statistics

RUNS = [
    {"rewrite": 820, "search": 240, "answer": 5900, "check": 1050},
    {"rewrite": 790, "search": 260, "answer": 6400, "check": 990},
    {"rewrite": 840, "search": 230, "answer": 6100, "check": 1120},
    {"rewrite": 810, "search": 2900, "answer": 5800, "check": 1010},
    {"rewrite": 830, "search": 250, "answer": 6250, "check": 1080},
]
totals = [sum(run.values()) for run in RUNS]
print("Median total:", statistics.median(totals), "ms")
print("Slowest total:", max(totals), "ms")
for stage in RUNS[0]:
    share = sum(run[stage] for run in RUNS) / sum(totals) * 100
    print(f"{stage:<8} {share:5.1f}% of all waiting time")
median_search = statistics.median(run["search"] for run in RUNS)
print("Median search:", median_search, "ms, but one run took", max(run["search"] for run in RUNS), "ms")

Output

Median total: 8410 ms
Slowest total: 10520 ms
rewrite    9.4% of all waiting time
search     8.9% of all waiting time
answer    69.7% of all waiting time
check     12.0% of all waiting time
Median search: 250 ms, but one run took 2900 ms

The median search time is 250 ms, so a median-only dashboard looks healthy. The one 2900 ms run is what the user who waited felt, which is why the 95th percentile matters.

What are the usual fixes, and what do they cost?

Once the slow step has a cause, pick the smallest fix that targets it. The chart maps each cause to its usual fix.

Each cause, its fix

Causes

Calls one after another

each call adds its wait

Long, uncached prompt

the first token comes late

Answer too long

more tokens to write

Fixes

Run calls side by side

when results don't depend on each other

Put stable text first

a stable prefix can be reused

Ask for only what's needed

the model writes less

Faster, measured again

keep it only if numbers move

  1. 1Calls with no dependency on each other run side by side.
  2. 2The stable part of the prompt is reused, so the first token comes sooner.
  3. 3The model is asked for only the detail the user needs.
  4. 4The side-by-side calls are timed again to confirm they helped.
  5. 5The cached prompt is timed again on the same requests.
  6. 6The shorter answer is timed again on the same requests.
Three common causes, each with a fix that targets it, and one check at the end. Measure the same requests before and after each fix, so the change is judged on the same work.
  1. 1

    Run independent work at the same time

    OpenAI's guide says to run independent work concurrently. Two lookups that don't need each other can start together, and the answer waits only for the slower one.

  2. 2

    Cache the stable part of the prompt

    Prompt caching can reuse an eligible exact match at the start of the prompt, so instructions, examples and tool definitions go first and stay unchanged.

  3. 3

    Ask for less text

    OpenAI's guide says that on supported models in its Responses API (its request format), a setting called text.verbosity can be lowered for shorter answers. Users rarely need the long version.

  4. 4

    Let code answer what it already knows

    An order's status or a refund that already went through doesn't need a model at all. OpenAI's guide says to use application code when you already know the answer.

  5. 5

    Stream the reply

    Streaming lets the user start reading before generation finishes. The wait feels shorter, even though the full answer takes as long to finish.

Anthropic's caching also reuses a matching prefix, but you choose how the cache mark goes in. Automatic caching means one cache_control field on the request, and the system moves the breakpoint to the last cacheable block as conversations grow. Explicit caching puts cache_control at the end of the stable text, so later requests that start the same way can reuse it. Changing text, such as a timestamp or the new user message, goes after that mark. To check it worked, look at cache_read_input_tokens, which counts the tokens taken from the cache for that request.

Each fix has a cost. Caching needs the prompt to stay the same. Starting a lookup before you know it is needed can waste work on a wrong guess, so start only read-only lookups you can discard. A short answer can drop detail a reader needs. Measure each change on the same requests before you keep it.

How would you find a slowdown that only happens at 9 am?

A coding agent that runs in the team's automatic build checks, called CI, gets slow every weekday at 9 am, when the whole team pushes code. The daily average hides it, so I split the timings by hour and compare the 95th percentile for each hour.

Next I check the model server as well as the app. vLLM's metrics include KV cache usage, which shows what fraction of the server's working memory for requests in progress is in use. Sometimes vLLM puts a request back in the waiting queue to make room for other requests, and its docs call that state PREEMPTED.

  • If the queue is long

    Capacity or fewer jobs at once

    Test running fewer agent jobs at the peak, or more server capacity, and measure the cost first.

  • If one step stalls

    Fix that step

    A search or a tool call that spikes at peak hours gets its own timeout and retry rules.

What does the interviewer want to hear?

A strong answer covers

  • Measure first: time each step, from the user's click to the last word.
  • Know time to first token and total time, and why they differ.
  • Compare the median with the 95th percentile.
  • Name the usual causes: calls one after another, long uncached prompts, long answers.
  • Fix one thing, time it again, and keep it only if the numbers move.
  • Name the cost of each fix, such as the rule caching needs or work wasted on a wrong early lookup.

Common traps

  • Trap"Switch to a faster model first."

    BetterMeasure first. A faster model won't help if the slow step is a search stall or three calls in a row.

  • Trap"The average response time looks fine."

    BetterCheck the 95th percentile. The average can hide the slow runs that users remember.

  • Trap"Make the prompt shorter, always."

    BetterOnly when input length is the cause. Cutting facts from a prompt can make answers wrong.

Can you spot the slow step?

Spot the right plan

A team wants to know why one question takes 14 seconds. Which plan finds the slow step?

Quick check

A pipeline's median is 2 seconds, its p95 is 14 seconds, and the search step stalls only at peak hours. What do you check first?

Can you answer these from memory?

Flash cards · tap a card to flip it

1 / 6

What will they ask next?

  1. Q316TTFT vs tokens/sec vs total latency?12 min
  2. Q317The latency vs throughput trade-off?Coming soon
  3. Q088What is prompt caching, and how does it save money?13 min
  4. Q260What is tracing for LLM apps?10 min
  5. Q344What is a p95/p99 latency budget?Coming soon
  6. Q340How do reasoning tokens affect cost and latency?Coming soon

Learn it in depth

Last updated on 26 November 2026

Running an AI product that feels slow?

I design and build AI agents and the systems behind them, including the timing and tracing that show where the wait comes from. Book a short call and tell me what feels slow.