Prompt
How do I find the bottleneck in a web app under load
Latest observation
To find the bottleneck in a web app under load, work from symptom → measurement → correlation → isolation. The goal is to identify where time is spent and what resource saturates first.
1) Define what “bottleneck” means
First decide which problem you’re chasing:
- High latency: requests get slower under load
- Low throughput: system stops scaling
- Errors/timeouts: requests fail once load rises
- Queueing: requests wait before being processed
You need a baseline metric like:
- p50 / p95 / p99 latency
- requests per second (RPS)
- error rate
- CPU, memory, disk, network, DB metrics
2) Reproduce the issue with a controlled load test
Use a load generator such as:
- k6
- JMeter
- Locust
- wrk / hey
- Gatling
Increase traffic gradually:
- 10 RPS → 50 → 100 → 200, etc.
- Watch where latency rises sharply or errors start
This helps identify the breakpoint where saturation starts.
3) Check the usual suspects in order
Look at each layer while load increases.
Application
- CPU usage
- thread pool / worker pool saturation
- event loop lag (Node.js)
- GC pauses
- lock contention
- slow code paths
- excessive serialization/deserialization
Database
- slow queries
- missing indexes
- too many queries per request
- connection pool exhaustion
- lock waits / deadlocks
- high buffer/cache misses
Cache
- cache hit rate
- cache stampede
- Redis/Memcached latency
- serialization overhead
Infrastructure
- CPU throttling
- memory pressure / swapping
- disk I/O wait
- network latency / packet loss
- container limits / autoscaling delays
4) Use tracing to find where request time goes
Distributed tracing is one of the best ways to find bottlenecks.
Use:
- OpenTelemetry
- Jaeger
- Zipkin
- Datadog / New Relic / Grafana Tempo
Trace a slow request and inspect spans:
- app processing time
- DB call duration
- external API calls
- queue delays
- cache access time
If one span dominates under load, that’s likely the bottleneck.
5) Profile the application
If the app itself is slow, profile it under load:
For CPU-bound issues
Use:
- flame graphs
- sampling profilers
pprof(Go)- async-profiler (Java)
- perf (Linux)
- cProfile (Python)
Look for:
- expensive functions
- repeated allocations
- JSON parsing
- regex
- encryption/compression
- excessive logging
For memory/GC issues
Look for:
- high allocation rate
- frequent garbage collection
- memory leaks
- object churn
6) Inspect database performance
Common DB bottlenecks:
- full table scans
- missing indexes
- N+1 queries
- large result sets
- too many round trips
- lock contention
Use:
- EXPLAIN / EXPLAIN ANALYZE
- slow query logs
- query plans
- DB monitoring dashboards
If latency rises with load and DB CPU or lock time is high, the DB may be the bottleneck.
7) Watch queueing and pool saturation
A lot of “slow app” problems are actually waiting problems:
- request queues
- thread pools
- DB connection pools
- HTTP client pools
- message queues
Signs:
- requests spend time queued before execution
- pool utilization stays at 100%
- latency increases while CPU may not
If pools are saturated, adding more traffic only increases waiting time.
8) Compare resource saturation vs latency
A useful rule:
- CPU near 100% → CPU bottleneck
- DB CPU or lock time high → DB bottleneck
- High I/O wait → disk bottleneck
- Memory pressure/swap/GC → memory bottleneck
- Pool saturation with moderate CPU → concurrency bottleneck
- External API latency high → dependency bottleneck
9) Bisect the request path
If you still can’t tell, isolate components:
- bypass cache
- bypass DB with mock data
- disable external calls
- remove nonessential middleware
- test a single endpoint
- test one instance only
This helps identify which dependency causes the slowdown.
10) Make sure your observability is good enough
At minimum, collect:
- request latency histogram
- throughput
- errors
- CPU, memory, disk, network
- DB query timing
- pool utilization
- GC stats
- external dependency timings
Without these, bottleneck hunting becomes guesswork.
A practical workflow
- Run a load test
- Observe when latency jumps
- Check CPU, memory, I/O, and pool utilization
- Trace a slow request
- Profile the hottest code path
- Check DB slow queries and locks
- Fix the biggest contributor
- Repeat
Common root causes
- missing DB indexes
- N+1 queries
- too much synchronous work in request path
- insufficient connection pool size
- external API dependency
- poor caching strategy
- high GC due to allocations
- single-threaded bottleneck
- logging too much under load
If you want, I can give you:
- a step-by-step checklist
- a tooling stack by language
- or a debug plan for a specific stack like Node.js, Python, Java, Go, or .NET.