Prompt
I need a better way to find the root cause of latency spikes in production, what should I set up?
Latest observation
To find the root cause of latency spikes in production, you’ll want end-to-end observability with correlation across metrics, logs, and traces. The goal is to answer, quickly:
- What got slow?
- Where in the request path did it slow down?
- What changed at that time?
- Was it caused by code, dependencies, infrastructure, or traffic?
What to set up
1) Distributed tracing
This is usually the biggest win for latency spikes.
Set up:
- OpenTelemetry instrumentation in your services
- A tracing backend such as:
- Grafana Tempo
- Jaeger
- Datadog APM
- New Relic
- Honeycomb
- Zipkin
Make sure traces include:
- request IDs / trace IDs
- service name
- endpoint / operation name
- latency per span
- downstream dependency calls
- error tags
- retries, timeouts, and queue wait time
Why it helps:
- Lets you see exactly which downstream call or internal span caused the spike
- Makes it easy to distinguish app time vs database time vs external API time
2) High-cardinality latency metrics
Standard average latency is not enough. You need percentiles and breakdowns.
Track:
- p50, p95, p99, p99.9
- latency by:
- endpoint
- service
- region / zone
- tenant/customer
- status code
- dependency
- request rate, error rate, saturation
Use a metrics system like:
- Prometheus + Grafana
- Datadog Metrics
- New Relic Metrics
- CloudWatch + dashboards
Important:
- Prefer histograms / summaries over averages
- Add RED metrics for services:
- Rate
- Errors
- Duration
3) Correlated structured logs
Logs should be searchable and tied to traces.
Set up logs with:
- trace ID
- span ID
- request ID
- service name
- endpoint
- user/tenant identifier if appropriate
- error codes
- retry counts
- timeout info
- queue depth / lock contention if relevant
Use structured logging in JSON, and centralize them in:
- ELK / OpenSearch
- Loki
- Datadog Logs
- Splunk
- Cloud logging tools
Why it helps:
- When a trace shows a slow span, logs tell you the exact error, timeout, or retry pattern
- Useful for catching application-level causes like GC pauses, thread pool exhaustion, or lock contention
4) Infrastructure and saturation monitoring
Latency spikes are often caused by resource pressure.
Monitor:
- CPU usage and throttling
- memory usage and GC pauses
- disk I/O latency
- network latency and packet loss
- container restarts / OOM kills
- thread pool / connection pool saturation
- queue depth
- database pool usage
- cache hit rate
- load balancer / ingress latency
If you’re on Kubernetes, also monitor:
- pod restarts
- node pressure
- CPU limits vs usage
- HPA scaling delays
- etcd / control plane issues if relevant
5) Dependency-specific telemetry
Often the root cause is a downstream service, DB, or cache.
For each important dependency, track:
- latency
- error rate
- saturation
- timeouts
- retries
- circuit breaker opens
- connection pool wait time
Examples:
- Database: query latency, slow queries, lock waits, buffer/cache hit rate
- Redis: command latency, eviction rate, hit rate
- Kafka: consumer lag, produce/consume latency
- External APIs: request latency and error rate
6) Change correlation
You need a way to see what changed around the spike.
Track and correlate:
- deployments
- config changes
- feature flag changes
- autoscaling events
- infrastructure changes
- dependency version updates
- schema migrations
Best practice:
- annotate dashboards with deploy markers
- log config and flag changes
- keep a timeline of production changes
7) SLOs and alerting on symptoms, not just causes
Set SLOs for user-facing latency, such as:
- 95% of requests under X ms
- 99% of requests under Y ms
Alert on:
- sustained p95/p99 regression
- elevated error rate
- saturation indicators
- dependency timeouts
Avoid alerts only on CPU or memory unless they’re clearly tied to user impact.
Recommended minimal stack
If you want a practical baseline:
- OpenTelemetry for traces + metrics + logs correlation
- Prometheus + Grafana for dashboards and alerts
- Tempo or Jaeger for tracing
- Loki or ELK/OpenSearch for logs
If you want a managed option:
- Datadog or New Relic can cover most of this with less setup effort
How to investigate a spike when it happens
- Check the latency dashboard for the exact time and affected endpoints
- Compare p95/p99 against error rate and traffic volume
- Open traces for slow requests
- Identify the slow span:
- DB?
- cache?
- external service?
- queue?
- app code?
- Check logs for retries, timeouts, lock waits, GC pauses, or saturation
- Look at infra metrics for CPU throttling, memory pressure, disk/network issues
- Check deploys/config changes around that time
- Confirm the root cause with before/after evidence
If you want the best “first investment”
Start with:
- distributed tracing
- p95/p99 latency dashboards
- request/log correlation
- deploy/change annotations
That combination usually gives the fastest path to root cause.
If you want, I can also suggest:
- a specific production observability stack for your cloud/provider
- a Kubernetes setup
- or a step-by-step implementation plan for OpenTelemetry.