P95 Latency
Tail latency targets for TTFT and end-to-end response time under load.
In plain words
p95 latency is how long the slowest 1 in 20 requests takes; looking at it shows the bad experiences that averages hide.
Think of it like…
A bus service: the average journey is fine, but if one trip in twenty takes triple the time, riders remember the bad trips and start taking cars.
Where you’ve seen it
From 100,000 daily requests the team sees mean 3.0 s, p50 2.1 s, p95 6.8 s and p99 14.0 s, so 5,000 requests a day take longer than 6.8 s. Traces show why: the LLM call has TTFT 0.6 s and decodes at about 150 tokens per second, so a typical 420-token answer takes 0.6 + 420/150 = 3.4 s while a 1,200-token answer takes 0.6 + 8.0 = 8.6 s. Long answers, provider retries and a cold vector index explain most of the slowest requests. Actions: stream tokens (perceived wait drops to the 0.6 s TTFT), cap output length with a concise-answer instruction (average 420 to 300 tokens saves 0.8 s), cache a stable prompt prefix, run retrieval and a permissions check in parallel, and send the second attempt of a request after the 6.8 s mark (hedging). p95 falls from 6.8 s to 4.6 s against an SLO of 5 s.
Words you’ll hear
- Percentile (p50, p95, p99)
- The value below which that share of requests fall; p95 is the 95th.
- Time to first token (TTFT)
- Delay from sending the request to receiving the first output token.
- Tail latency
- The slowest requests, where timeouts and bad experiences concentrate.
- SLO
- A target such as p95 under 5 seconds measured over a window.
Visual diagram
Theory & deep dive
Measuring it properly
Record latency per request and per stage (queue wait, retrieval, each model call, tools) as histograms and compute percentiles from the histogram, not from averages. Percentiles don't add: the p95 of a pipeline isn't the sum of its stages' p95s, and averaging p95 values across servers is wrong; aggregate the underlying histograms or raw samples. For streaming responses track TTFT and inter-token latency separately from total time, and slice by input and output length, model, feature and cache hit, because a single combined number mixes different workloads. For agents, measure end-to-end task time and the number of steps, since the tail is dominated by runs with many steps or retries.
Set an SLO (for example p95 under 5 s and p99 under 10 s over 28 days) and alert on burn rate rather than single spikes. Remember that the tail grows with fan-out: if a request makes 5 independent calls and each has a 5% chance of being slow, the chance that at least one is slow is 1 − 0.95⁵ = 22.6%, which is why agents and multi-call pipelines have worse tails than any single call.
With TTFT 0.6 s and 150 tokens/s: 300 tokens → 0.6 + 2.0 = 2.6 s; 420 → 3.4 s; 1,200 → 8.6 s. Cutting average output from 420 to 300 tokens saves 0.8 s per request without touching the model.
Reducing latency
Levers by impact: shorten outputs (concise-answer instructions, max-token limits, structured outputs with short fields); stream so users see text after TTFT; cache (prompt-prefix caching lowers TTFT and cost for long shared prefixes, and a semantic or exact response cache skips the call); route easy requests to a smaller, faster model; parallelise independent work (retrieval alongside moderation) and avoid serial chains of model calls; trim context (fewer, better chunks reduce prefill time); and use speculative decoding or faster serving where you control the model.
Tame the tail: set timeouts per stage with fallbacks (a smaller model or a cached answer), use retries with jittered backoff and a retry budget so retries don't cause storms, consider request hedging (send a duplicate after the p95 delay and use whichever finishes first, costing about 5% extra calls), keep warm connections and pre-warm indexes after deploys, and apply admission control or queues when providers rate-limit. Always weigh latency against quality and cost: reasoning models and bigger contexts improve answers but lengthen both median and tail, so set per-feature budgets rather than a single global target.
If p95 is 6.8 s, issue a second identical request when the first hasn't returned by 6.8 s and take the earlier response. About 5% of requests are duplicated (+5% calls) and the p99 drops sharply because slow outliers are often provider-side queue delays that don't repeat.
How it works, step by step
Step 1 of 41. Instrument stages
Record per-stage timings, TTFT, token counts and cache hits in histograms and traces.
- Slice
- length and model
When to use it & trade-offs
What it is
p95 latency is the response time that 95% of requests beat: 5% are slower. Percentiles (p50, p95, p99) describe the tail, which is what unhappy users actually experience, while the mean hides it. LLM latency has an unusual shape: time to first token (TTFT) depends on input length, queueing and caching, and then each output token adds a roughly constant decode time, so response length drives total time, and multi-step agents and retries stretch the tail further. Managing p95 means measuring it per stage, setting an SLO, and attacking the biggest contributors.
Why it matters: Users perceive slowness in the worst moments, and a feature with a 2-second median and a 14-second p99 feels unreliable. Long-tail latency also causes timeouts, retries and cascading load. In LLM products latency trades directly with quality (bigger models, more reasoning, more retrieval) and cost, so engineers need to quantify the budget, find where time goes and choose techniques such as streaming, caching, routing and parallelism deliberately.
When to reach for it
- Setting SLOs for AI features
- Explaining a slow tail and choosing fixes
- Budgeting latency across a multi-step pipeline
When to avoid or be careful
- Reporting only the mean
- Averaging percentiles across instances
- Retrying without jitter and a budget
Latency techniques
Strengths: Users see output after TTFT; no quality loss.
Watch out: Doesn't reduce total time or backend load.
Strengths: Cuts both latency and cost.
Watch out: Needs stable prefixes; staleness risk for response caches.
Strengths: Fast, cheap handling of simple cases.
Watch out: Routing errors can hurt quality.
Interview signals & numbers to know
When this topic comes up
- “Some requests take 15 seconds”
- “What's our p95?”
- “Time to first token”
- Agents with many steps
- Provider rate limits and retries
Benchmarks & rules of thumb
- 2.1 / 6.8 / 14.0 s
- p50 / p95 / p99 in the example
- 0.6 + tokens ÷ 150
- seconds for TTFT plus decode in the example
- 22.6%
- chance at least one of 5 calls is in its slowest 5%
Common mistakes & follow-ups
Common interview mistakes
- Computing the mean latency and declaring the feature fast.
- Adding stage p95s to estimate total p95.
- Letting long outputs run unbounded.
Likely interviewer follow-ups
- How would you reduce p95 latency of an LLM feature?
- Why do multi-step agents have worse tail latency?
- How is perceived latency different from actual latency?
Knowledge check
Put it into practice
Practice related interview Q&A
Apply P95 Latency with generative AI interview Q&A and hands-on practice.