Prompt
How do I troubleshoot high latency in a microservices call chain
Latest observation
To troubleshoot high latency in a microservices call chain, work from symptom → hop-by-hop timing → bottleneck classification → fix/verify.
1) Identify where the latency is introduced
Start by measuring the total request latency and then break it down by each hop.
Look at:
- Client-side latency
- API gateway / ingress
- Each service in the chain
- Database / cache / external API calls
- Queue / message broker delays if async steps are involved
Use distributed tracing if you have it:
- OpenTelemetry, Jaeger, Zipkin, Datadog APM, New Relic, etc.
- Find the trace with the slowest p95/p99 requests
- Identify which span contributes the largest share of time
If you don’t have tracing, add it first. Without it, troubleshooting is much harder.
2) Determine whether the latency is in:
A. Network/transport
Signs:
- High time before first byte
- Spikes between services
- Retries/timeouts causing amplification
Check:
- DNS resolution
- TLS handshake overhead
- Cross-zone / cross-region traffic
- Service mesh or proxy overhead
- Packet loss, retransmits, MTU issues
- Connection reuse / keep-alive behavior
B. Service compute
Signs:
- High CPU
- Increased GC pauses
- Thread pool exhaustion
- Event-loop blocking
- Container throttling / CPU limits
Check:
- CPU usage and throttling
- Memory pressure
- GC logs / pause times
- Thread pool queue depth
- Saturation of worker pools
- Lock contention
C. Downstream dependency
Signs:
- One downstream service dominates the trace
- Slow DB query, cache miss, or external API
Check:
- DB query plans
- Index usage
- Connection pool saturation
- Cache hit rate
- External service latency and rate limits
D. Retry / timeout amplification
Signs:
- Latency worsens under load
- Multiple identical downstream calls in a trace
- Error rate is low but latency is high
Check:
- Retries with exponential backoff
- Circuit breaker settings
- Fan-out patterns
- N+1 request behavior
- Hedged requests causing extra load
3) Compare p50 vs p95 vs p99
This helps classify the problem:
- p50 high: systemic issue, likely capacity or slow dependency
- p95/p99 high only: tail latency, often queueing, GC, cold caches, retries, or noisy neighbors
Look for:
- Burst traffic
- Cold starts
- Autoscaling lag
- Spot/preemptible instance churn
- Uneven load balancing
4) Check the request path for hidden serialization
A “microservices chain” can accidentally become serial:
- Service A calls B then C then D sequentially
- Fan-out is done one call at a time instead of in parallel
- Shared locks force requests to wait
- Synchronous logging or tracing blocks the request path
Fixes:
- Parallelize independent calls
- Reduce synchronous work in the critical path
- Make logging non-blocking
- Cache repeated lookups
5) Inspect resource saturation at each hop
At each service, check:
- CPU
- Memory
- Disk I/O
- Network I/O
- Open file descriptors
- Thread/connection pool usage
Common patterns:
- CPU near 100%: compute bottleneck or too little capacity
- Connection pool maxed: waiting for DB/http connections
- High GC: memory pressure or allocation-heavy code
- Queue depth rising: consumers slower than producers
6) Look for misconfigurations
These often cause “mysterious” latency:
- Small connection pools
- No HTTP keep-alive
- Too-low request timeouts causing retries
- Overly aggressive circuit breakers
- Sidecar/service mesh misconfiguration
- DNS TTL or lookup issues
- Load balancer health check misbehavior
7) Validate with targeted experiments
Try one change at a time:
- Bypass a suspected dependency
- Increase connection pool size
- Temporarily disable retries
- Move traffic to the same zone/region
- Increase CPU/memory limits
- Reduce logging/tracing overhead
- Warm caches or prefetch data
Measure before/after using:
- p50/p95/p99 latency
- throughput
- error rate
- CPU/memory/throttling
- downstream service time
8) Use logs and traces together
For each slow trace, correlate:
- Trace ID
- Request ID
- Service logs
- DB slow query logs
- Infrastructure metrics
This often reveals:
- A specific slow query
- A retry storm
- A timeout from one dependency
- A GC pause on one instance
9) Typical root causes
Most common causes of high latency in microservice chains:
- Slow database query
- Too many sequential service hops
- Retry storms
- Connection pool exhaustion
- GC pauses or CPU throttling
- Cross-region calls
- Cold starts / autoscaling delays
- Cache misses
- Service mesh / proxy overhead
- Thread pool exhaustion
10) Practical triage checklist
If you want a fast path:
- Find a slow trace
- Identify the slowest span
- Check that service’s CPU, memory, GC, and pool metrics
- Check downstream calls from that service
- Look for retries, timeouts, or serial fan-out
- Inspect DB/cache/external dependency metrics
- Compare normal vs slow requests
- Test one fix and re-measure
If you want, I can also give you:
- a step-by-step incident playbook
- a Prometheus/Grafana metric checklist
- or a sample OpenTelemetry tracing workflow for microservices latency debugging