LLM Latency & Serving Hub

P95 latency, timeout, throughput: serving optimization playbook

This hub gathers the playbook: bottleneck analysis, streaming and perceived latency, caching, concurrency, queueing, canary and rollback, observability and tracing. For teams with P95 spikes, timeouts, or high compute cost.

Common latency & serving pains

📈P95 latency spikes; why LLM p95 latency spikes under load
Timeouts in RAG pipeline; how to reduce timeout
🔒Throughput too low; concurrency limits hit
💸Compute cost high; serving inefficient
🌊Streaming vs non-streaming latency tradeoffs unclear
⏱️Latency budgeting

End-to-end: retrieval → generation

Allocate latency budget per pipeline stage. Know where time goes before optimizing.

1

Retrieval

Vector search, BM25, reranking. Measure p50/p95 per step. Often 100–500ms depending on top-k and reranker.

~100–500ms
2

Prompt assembly

Context injection, template rendering. Usually fast; can spike with large context.

~10–50ms
3

Prefill (TTFT)

Time to first token. Model loading, context encoding. Dominant for long context.

~200ms–2s
4

Decode (generation)

Token-by-token. Throughput limited by model + hardware. Streaming improves perceived latency.

Variable by length
5

Post-processing

Citation extraction, formatting, guardrails. Can add 50–200ms.

~50–200ms
Bottlenecks + diagnostics

Common bottlenecks (and how to find them)

Why LLM p95 latency spikes? Trace each step. Isolate the dominant constraint.

1

Retrieval slow

Symptoms: RAG pipeline timeout; retrieval dominates end-to-end.

Diagnostics: Trace retrieval step; check top-k, reranker latency, vector index size.

Fix: Reduce top-k, add caching, optimize reranker or skip for simple queries.

2

Context too large

Symptoms: Prefill/TTFT spikes; p95 latency blows up on long context.

Diagnostics: Measure context length distribution; correlate with latency.

Fix: Truncate, summarize, or chunk smarter. Reduce max context where possible.

3

Model saturation

Symptoms: Throughput plateaus; queueing; timeouts under load.

Diagnostics: GPU/utilization; queue depth; concurrent request count.

Fix: Scale replicas, batch requests, or add queue with timeout.

4

Cold start / model load

Symptoms: First request very slow; periodic spikes.

Diagnostics: Trace model load time; check autoscaling min replicas.

Fix: Keep warm replicas; preload models; avoid scale-to-zero for latency-sensitive paths.

💾Caching layers

Retrieval, prompt, response

Caching strategy for LLM responses and pipeline steps. Where to cache and the tradeoffs.

Retrieval cache

Cache embedding + vector results for repeated/similar queries. Semantic cache or exact match.

Tradeoff: High hit rate on FAQ-like traffic; invalidation on corpus update.

Prompt / context cache

KV cache or prompt caching (e.g. OpenAI). Reuse encoded context across requests.

Tradeoff: Saves prefill for long context; depends on provider support.

Response cache

Cache full responses for identical queries. Simple but limited coverage.

Tradeoff: Best for deterministic, low-variance outputs; watch staleness.
Concurrency & throughput

Queueing, limits, throughput optimization

Concurrency limits, queueing behavior, and throughput optimization. Model serving infrastructure constraints.

Concurrency limits

Model serving has finite throughput. Limit concurrent requests per instance; queue the rest. Reject or timeout excess.

Queueing

Queue requests when at capacity. Set queue timeout to avoid long waits. Monitor queue depth and wait time.

Throughput optimization

Batching, continuous batching, speculative decoding. Trade latency for throughput where acceptable.

Rate limits

Protect backend from overload. Per-user, per-tenant, or global. Graceful degradation when exceeded.

🚦Release safety

Canary, rollback, rate limits

Ship new models and configs safely. Canary rollout, rollback plan, and protective limits.

Canary rollout

Route small % of traffic to new model/config. Compare latency, errors, quality. Roll back if regressions.

Rollback plan

One-click or automated rollback. Feature flags, model version routing. Document rollback triggers.

Rate limits on new releases

Throttle traffic to new version initially. Ramp up as confidence grows.

Circuit breaker

Stop sending traffic to failing instance. Fail fast; avoid cascading timeouts.

📊Observability

Traces, logs, SLOs

Tracing LLM pipeline end-to-end. Structured logs. SLOs and dashboards for latency and throughput.

Distributed tracing

Trace LLM pipeline end-to-end: retrieval → prefill → decode → post-process. Span per step; trace ID across services.

Structured logs

Log latency per step, token counts, model version, errors. Queryable for debugging and SLO reporting.

SLOs

p95 latency SLO, error rate SLO, availability. Alert on burn rate. Track per cohort if needed.

Dashboards

Latency by step, throughput, queue depth, cache hit rate. Correlate with releases and traffic.

Streaming vs non-streaming

Streaming improves perceived latency (TTFT matters for UX) even if total time is similar. Measure both end-to-end and time-to-first-token.

Need latency optimization or serving audit?

We help teams diagnose P95 spikes, reduce timeouts, and optimize LLM serving infrastructure.