Prompt
How do I find which service is causing latency in a distributed system?
Latest observation
To find which service is causing latency in a distributed system, you usually want to trace the request end-to-end and then isolate where the extra time is being spent. Here’s a practical approach:
1) Start with the symptom
Determine:
- Is the latency affecting all requests or only certain routes/users/regions?
- Is it consistent or spiky?
- Is it on the frontend, API gateway, or downstream service?
Check basic service metrics first:
- p50 / p95 / p99 latency
- error rate
- request volume
- CPU, memory, disk, network
- DB/cache latency
2) Use distributed tracing
The most effective way is with tracing tools like:
- OpenTelemetry
- Jaeger
- Zipkin
- Datadog APM
- New Relic
- Grafana Tempo
A trace shows the full path of a request across services and how long each span took.
Look for:
- the longest span
- gaps between spans
- services with unusually high self time
- repeated downstream calls
- retries, timeouts, or queueing delays
3) Compare service-to-service timing
If service A calls B, C, and D:
- measure each downstream dependency
- compare response times across calls
- identify which downstream call adds the most delay
Sometimes the slow service is not the one with the highest total latency, but the one causing backpressure or retry amplification.
4) Check for common bottlenecks
Latency often comes from:
- database queries: slow SQL, missing indexes, lock contention
- network issues: packet loss, DNS delays, TLS handshake overhead
- thread pool exhaustion: requests waiting for worker threads
- GC pauses: in JVM/.NET/Go depending on runtime
- caching problems: cache misses or thundering herd
- external APIs: third-party slowness
- queues: consumer lag or queue buildup
5) Correlate with logs and metrics
Use the trace/request ID to join:
- logs
- traces
- metrics
This helps you see whether the latency is due to:
- waiting on a lock
- retrying a failed call
- rate limiting
- service saturation
6) Look for patterns
Ask:
- Does latency increase only at peak traffic?
- Is it tied to one region or AZ?
- Does it happen for specific endpoints?
- Does it correlate with deployments?
If it started after a deploy, compare:
- old vs new version
- config changes
- dependency changes
7) Isolate by removing dependencies
If tracing isn’t enough:
- temporarily bypass a service
- stub/mock a downstream dependency
- use feature flags to disable certain calls
- run synthetic tests against each service
This helps confirm whether a specific service or dependency is the culprit.
8) A useful rule of thumb
The slowest service is not always the root cause.
Often the root cause is:
- a dependency that’s slow,
- a resource exhaustion issue,
- or retries multiplying a small delay into a big one.
Quick workflow
- Identify the slow endpoint.
- Pull a trace for a slow request.
- Find the span with the largest duration or wait time.
- Check downstream dependencies of that span.
- Correlate with logs/metrics for saturation, retries, or DB slowness.
- Confirm by load testing or isolating the dependency.
If you want, I can also give you:
- a step-by-step debugging checklist
- a sample OpenTelemetry/Jaeger workflow
- or a Python/Go/Java example for instrumenting a distributed system.