Debugging latency spikes in microservices: p95, p99, queueing, fan-out and slow dependencies

Why averages hide the slow requests your users notice, how fan-out and queueing turn small delays into p99 spikes, and a step-by-step workflow from percentile to trace to root cause.

Obseria TeamObseria
Summary
  • Latency spikes in microservices are usually invisible in averages and only show up in p95 and p99 percentiles, which must be computed from merged histograms rather than averaged across instances.
  • Fan-out multiplies the chance that a request waits for at least one slow dependency, and queueing near saturation makes wait times grow much faster than load.
  • A reliable workflow starts at the p99 SLI, compares time windows and dimensions, jumps from histogram buckets to traces via exemplars and ends at the critical path, a deployment or a saturated resource.

Latency spikes are among the most frustrating problems in a microservice architecture. Dashboards look green, the average response time barely moves, yet users complain that checkout "sometimes hangs" and a downstream team reports timeouts. The slow requests are real, but they live in the tail of the distribution, and the tools many teams look at first are built to hide them.

This guide explains how percentiles and histograms work, why p99 latency gets worse as your call graph grows, how queueing turns a busy resource into a latency cliff, which causes show up again and again, and how to debug a spike systematically. It ends with a symptom table, mitigation patterns and a copyable latency spike runbook.

Why averages hide latency spikes

An average compresses thousands of requests into one number. If 98 requests take 40 ms and 2 requests take 2,000 ms, the mean is about 79 ms (example numbers). That looks acceptable, but two users in a hundred waited two seconds. Averages are pulled by outliers just enough to look "a bit worse" and never enough to show how bad the slow requests actually were.

Percentiles answer a better question: how slow is the request that a given share of users experiences? The p50 (median) is the typical request, p95 is the value that 95 % of requests stay below, and p99 is the value only one request in a hundred exceeds. Our glossary entries on latency and percentiles cover the basics. For user-facing services, p95 and p99 are usually the numbers to put into an SLI, because a single page view or API workflow often triggers many requests, so many users hit the tail at least once.

Percentiles cannot be averaged

A common mistake is to compute p99 per pod and then average those values on a dashboard. That result is not the p99 of the service. If one pod has a p99 of 900 ms and nine pods are at 100 ms, the averaged value (180 ms) says nothing about the real tail. Percentiles of different subsets cannot be combined arithmetically; you need the underlying distribution.

That is why latency should be recorded as a histogram: counts of requests per latency bucket. Histograms from all instances can be summed bucket by bucket, and the percentile is calculated from the merged result. In Prometheus terms, with the OpenTelemetry metric http.server.request.duration:

# Correct: merge buckets across pods, then compute the percentile
histogram_quantile(0.99,
  sum by (le) (rate(http_server_request_duration_seconds_bucket[5m])))

# Misleading: averaging per-pod percentiles
avg(histogram_quantile(0.99,
  sum by (pod, le) (rate(http_server_request_duration_seconds_bucket[5m]))))

Keep in mind that a histogram percentile is an estimate within the bucket that contains it. Choose bucket boundaries around your SLO threshold, or use exponential (native) histograms, which adapt their resolution automatically.

Tail latency amplification: fan-out makes p99 everyone's problem

Tail latency in microservices is not just a property of each service; it is a property of the call graph. When a request fans out to N backends in parallel and has to wait for all of them, the response is as slow as the slowest call. Even if every backend is fast 99 % of the time, the chance of hitting at least one slow response grows quickly with N.

If each call independently has a 1 % chance of being slower than its p99, the probability that a request with N parallel calls hits at least one slow call is 1 - (0.99)^N. Example calculation (assuming independent calls and identical services):

Parallel calls (N)1 - 0.99^NShare of requests that wait for a p99-slow call
10.010about 1 %
50.049about 4.9 %
100.096about 9.6 %
500.395about 39.5 %
1000.634about 63.4 %

In other words, a backend's p99 becomes something close to the typical experience of a front end that calls 100 of them. Real systems are not perfectly independent (a shared database slows all calls at once), but the direction is the same. Sequential calls add up as well: five calls in a row each add their own tail. The practical consequences are to keep fan-out small, set budgets per hop and treat backend p99 and p99.9 as first-class signals.

Queueing: why latency explodes near saturation

Most latency spikes are not slow work but waiting: for a thread, a connection, a CPU slice or a lock. Queueing theory gives two intuitive tools for reasoning about this.

Little's Law states that the average number of requests in a system equals the arrival rate times the average time each request spends in it: L = λ × W. Example: a service receives 200 requests per second with an average latency of 50 ms, so about 10 requests are in flight. If a dependency slows down and latency rises to 500 ms at the same rate, 100 requests are in flight. A database pool of 50 connections is now exhausted, and new requests start to queue, which raises latency further.

Utilization drives wait time non-linearly. In a simple single-server queue model with random arrivals (M/M/1), the average response time is the service time divided by (1 - utilization). Example values for a 10 ms service time:

  • 50 % utilization: about 20 ms response time
  • 80 % utilization: about 50 ms
  • 90 % utilization: about 100 ms
  • 95 % utilization: about 200 ms

Real services are not M/M/1 queues, but the shape is universal: the last few percent of capacity are extremely expensive, and the tail grows even faster than the average. That is why saturation (pool usage, queue length, run queue) is a better early warning than utilization alone, and why a short traffic burst can cause a latency spike that lasts long after the burst ends, until the backlog drains.

Common causes of latency spikes

  • Slow dependencies and databases: a missing index, lock waits, a cache miss storm or a third-party API with its own incident. Usually visible as one span type dominating the trace.
  • Connection pool exhaustion: requests wait for a database or HTTP connection before any work starts. The wait often shows as a gap in the trace before the client span.
  • Garbage collection pauses: stop-the-world phases in the JVM, .NET or Go stall all requests on an instance at once.
  • CPU throttling: containers that exhaust their CFS quota are paused until the next period, even if the node has idle CPU. Check container_cpu_cfs_throttled_periods_total.
  • Noisy neighbors: another workload on the same node, disk or database consumes shared resources.
  • Retries and retry storms: each layer retries a slow call, multiplying load on the dependency that is already struggling. Without exponential backoff, jitter and retry budgets, a small slowdown turns into an overload.
  • Cold starts: new pods, serverless functions or freshly deployed JVMs with empty caches and unoptimized code serve their first requests slowly.
  • Lock contention: row locks in the database, mutexes in the application or a single synchronized resource serialize requests under load.
  • DNS: slow or failing lookups, short TTLs or the Kubernetes default ndots:5 causing several lookups per external hostname.

Symptom pattern, likely cause, what to look at

Symptom patternLikely causeWhat to look at
p99 rises, p50 stable, all endpointsGC pauses, CPU throttling, noisy neighborGC pause metrics, throttled periods, node-level CPU and I/O
p99 rises on one endpoint onlySlow query, slow dependency, code changeExemplar traces for that route, slowest span, recent deploys
Spike on a subset of pods or one zoneBad node, noisy neighbor, uneven load balancingBreakdown by pod, node and zone
Spike starts right after a releaseRegression, cold caches, new dependency callDeployment markers, latency by version, profile diff
Latency and in-flight requests rise togetherQueueing, pool exhaustionPool pending/active, queue length, Little's Law estimate
Traffic to a dependency jumps without user traffic changeRetry stormRetry counters, request rate per caller, error codes
Spikes at fixed intervalsCron jobs, batch exports, cache expiry, backupsScheduler logs, cache TTLs, database activity
Gaps in traces before the first child spanWaiting for thread, connection or lockPool metrics, thread dumps, continuous profiles
Slow first requests after scale-outCold starts, JIT warm-upLatency by pod age, readiness and warm-up settings

A debugging workflow from p99 to root cause

  1. Start from the p99 SLI. Confirm the spike on the user-facing metric (p95/p99 per endpoint from merged histograms), and check whether it actually burns error budget. This keeps you focused on impact.
  2. Compare time windows. Put the spike next to the same period yesterday or last week. Did traffic grow, did the latency distribution shift as a whole, or did only the tail widen?
  3. Break down by dimension. Split by endpoint, region, zone, version, pod and customer tier. A spike limited to one version points to a release; one limited to a node points to infrastructure.
  4. Jump from histogram to trace with exemplars. An exemplar attaches a trace ID to a sample in a histogram bucket, so you can click the slow bucket and open a real request from it instead of searching for one.
  5. Analyze the critical path. In distributed tracing, the critical path is the chain of spans that determines total duration. Ignore parallel spans that finished early; look for the longest span on that path and for gaps where nothing is recorded (often waiting).
  6. Correlate with changes. Deployment tracking shows whether the spike started with a deploy, a config change or a feature flag, and lets you compare latency by version directly.
  7. Go below the span. When a span is slow but has no child spans, continuous profiling shows whether time goes to CPU, locks, GC or I/O in that code path.

Mitigations: timeouts, hedging, bulkheads and backpressure

  • Timeouts and deadlines: every remote call needs a timeout shorter than the caller's. Propagate a deadline through the call chain (gRPC does this natively) so downstream services stop work nobody waits for anymore.
  • Hedged requests: for idempotent reads, send a second request to another replica if the first has not answered after roughly the p95. This cuts the tail at the cost of a small amount of extra load; limit how many requests may be hedged.
  • Bulkheads: separate pools per dependency or tenant so one slow backend cannot consume every thread or connection.
  • Circuit breakers: stop calling a failing dependency for a while and fail fast or fall back, instead of queueing requests behind it.
  • Backpressure and load shedding: bounded queues and early rejection (HTTP 429/503) keep the service in the region where latency is predictable rather than letting queues grow without limit.
  • Retry discipline: retry only at one layer, with exponential backoff, jitter and a retry budget.
  • Caching: cache hot reads close to the caller, and protect against stampedes with request coalescing and staggered expiry.

Copyable latency spike runbook

Latency spike runbook

LATENCY SPIKE RUNBOOK
1. Impact
   [ ] Which SLI is affected (p95/p99, endpoint, region)?
   [ ] Is the error budget burning? Start time of the spike?
2. Scope
   [ ] Compare with the same window yesterday / last week
   [ ] Break down by endpoint, region/zone, version, pod, node
   [ ] p50 also moving, or only the tail?
3. Changes
   [ ] Deployments, config changes, feature flags in the last 2 h
   [ ] Scale-out events, new pods (cold starts)?
4. Traces
   [ ] Open exemplar traces from the slow histogram buckets
   [ ] Follow the critical path; note the longest span and any gaps
   [ ] Same dependency slow in most exemplars?
5. Resources and queues
   [ ] Connection/thread pool pending and active counts
   [ ] CPU throttling, GC pauses, node CPU and I/O
   [ ] In-flight requests vs. normal (Little's Law: rate x latency)
   [ ] Retry rate and request rate to the slow dependency
6. Mitigate
   [ ] Roll back the suspect release or disable the flag
   [ ] Shed load, open circuit breaker, reduce retries, scale out
7. Follow-up
   [ ] Root cause with evidence, timeouts/budgets reviewed
   [ ] Alert or SLO adjusted, runbook updated

How Obseria helps debug latency spikes

Obseria is an OpenTelemetry-native observability platform, so latency histograms, exemplars and traces from your existing OpenTelemetry instrumentation arrive without a proprietary agent. Percentiles are computed from merged histograms, and from a slow bucket you can open the traces behind it, follow the critical path and see continuous profiles and deployments on the same timeline.

  • Obseria TopoGraph shows which services fan out to which dependencies, so you can see where tail latency accumulates.
  • Obseria Intelligence links a p99 spike to a deployment, a saturated pool or a slow dependency and shows the evidence for each conclusion.
  • SLOs with burn-rate alerts page on tail latency that actually affects users instead of on static thresholds.

You can try the full workflow on your own services with a free 14-day Obseria trial.

Share

Observability that delivers answers.

Start for free with OpenTelemetry, no credit card required.