Finding bottlenecks
Overview
A system is only as fast as its slowest part. If the database can handle 5,000 queries a second, it doesn’t matter that your app servers could handle 50,000. Finding that limiting component, the bottleneck, is the first step in any scaling problem, at work and in interviews.
What a bottleneck looks like
In this picture the database is the bottleneck. Adding app servers would not help; it would send even more queries to the database and make the queue longer.
Utilisation, saturation and errors
A practical way to check each resource is the USE method:
- Utilisation: how busy is it? (CPU 90%, disk 100% busy, network at 8 of 10 Gbit/s)
- Saturation: is work waiting? (run queue length, disk queue, threads waiting for a connection)
- Errors: is it failing? (timeouts, dropped packets, out-of-memory kills)
Check it for every resource on every component: CPU, memory, disk I/O, network and pools such as database connections or worker threads. Pools are a common hidden limit: a database with idle CPU can still be the bottleneck if every app server has only 10 connections and all are in use.
Follow the latency
Utilisation tells you who is busy; latency tells you who is making users wait. Trace a slow request and see where the time goes:
total 850 ms
├─ gateway 4 ms
├─ auth service 12 ms
├─ product service 30 ms
│ └─ database 780 ms ← here
└─ render 24 msDistributed tracing tools draw exactly this. As a component approaches saturation its p99 latency rises first, often before averages move, so watch the tail.
Common bottlenecks and first fixes
| Bottleneck | Symptoms | Typical first fixes |
|---|---|---|
| Database reads | High CPU or disk reads, slow queries | Indexes, caching, read replicas |
| Database writes | Lock waits, slow commits | Batch writes, queue them, shard |
| One hot row or key | One counter or celebrity profile overloaded | Split the counter, cache the hot key, spread load |
| App CPU | High CPU on all app servers | Add servers, optimise code, cache results |
| Network or bandwidth | Saturated links, large payloads | Compress, CDN, smaller responses |
| External service | Waiting on a slow API | Timeouts, caching, async calls |
| Connection or thread pools | Requests queue with idle CPU | Size pools correctly, reduce call time |
Fix in the right order
- Measure to find the actual bottleneck, not the one you assume.
- Do less work: remove unnecessary queries, fix N+1 query patterns, add indexes. These are cheap and often give 10× gains.
- Avoid repeated work: cache results that are read often and change rarely.
- Spread the work: add servers, replicas or shards.
- Measure again. Removing one bottleneck reveals the next. After adding a cache, the database may be fine but the cache network may be saturated.
Bottlenecks in interviews
During the deep-dive and wrap-up phases, interviewers often ask “where will this break first?”. A good answer uses your estimates:
“At 35,000 reads per second at peak, the app servers are fine; we can add more. The database is the first bottleneck. With a 90% cache hit rate it sees about 3,500 reads per second, which a primary plus two read replicas can handle. If the hit rate falls, the replicas are the next thing to watch.”
Two common follow-ups:
- “What if traffic grows 10×?” Walk through each component and say which one runs out first and how you’d scale it.
- “What about hot keys?” Explain how a single popular item can overload one cache node or one shard even when total load is fine, and how to spread it (replicating hot keys, local caches, splitting counters).
Recap
The bottleneck is the resource that runs out first, and it caps the whole system. Find it by checking utilisation, saturation and errors on every resource, and by following where latency goes. Fix it cheaply first (less work, caching), then spread the load, and measure again because the bottleneck always moves.
Diagnose the slowdown
An online shop slows down every evening. Dashboards show: app servers at 35% CPU, the Redis cache at 20% CPU with a 60% hit rate, the database at 90% CPU with disk reads at their limit, and the database connection pool on each app server often full. The slowest query is 'list products in a category, sorted by popularity'. What is the bottleneck, what evidence points to it, and what three changes would you try, in order?
Bottleneck:
Evidence:
Changes to try, in order:
1.
2.
3.Bottleneck: the database (CPU and disk I/O are saturated).
Evidence: 90% CPU and maxed-out disk reads on the database, full connection pools
(requests waiting for the database), while app servers and cache are mostly idle.
Adding app servers would make it worse by sending even more queries.
Changes to try, in order:
1. Fix the slow query: add an index that supports "category + popularity" (for example
on (category_id, popularity DESC)) so it stops scanning and sorting many rows.
2. Improve caching: the 60% hit rate is low for product listings. Cache category pages
(or the top N product IDs per category) for a minute or two, so most reads skip the DB.
3. Add read replicas and send listing queries to them, keeping the primary for writes.
(Bigger database hardware is a reasonable quick fix while doing 1-3.)Summary
- A bottleneck is the resource that runs out first; it limits the throughput of the whole path.
- Check utilisation, saturation (queues and waiting) and errors for each resource: CPU, memory, disk, network and connections.
- Rising tail latency is often the first sign of saturation.
- Fix the real bottleneck first; scaling other components can make things worse.
- Every fix moves the bottleneck somewhere else, so measure again after each change.