StackMonkey

How to find the bottleneck in a system design

The bottleneck is the busiest component, not the slowest. Work it out with utilisation and Little's Law, using a worked example with computed queueing numbers.

By StackMonkey, . 12 minute read.

Utilisation of five components at 2,000 requests a second, with Postgres highlighted at 75%, next to a curve showing queueing delay rising sharply as utilisation approaches 100%

The bottleneck in a system design is the component with the highest utilisation: the one whose arrival rate is closest to what it can process. It is often not the slowest component. A payment API that takes 300 ms per call can be nearly idle, while a database answering in 20 ms is the thing about to fall over. To find the bottleneck, work out each component's utilisation, then remember that latency does not grow evenly with load: it explodes as utilisation approaches 100%.

Key takeaways

  • Utilisation is arrival rate × service time ÷ number of workers. The component with the highest utilisation is the bottleneck.
  • Queueing delay grows non-linearly. In a single-server queue, time in system is 2× the service time at 50% utilisation, 10× at 90% and 20× at 95%.
  • Little's Law (L = λW) links how many requests are in flight, the arrival rate and the latency, so you can check one from the other two.
  • Fixing a bottleneck moves it. After every fix, recompute utilisation for every component.

What is a bottleneck in system design?

A bottleneck is the component that limits how much traffic the whole system can handle. It is the first component to run out of capacity as load rises, so its queue grows first and its latency climbs first.

A common definition says a system "can only process as fast as its slowest performing component" (Microsoft Learn, How to Investigate Bottlenecks). That is true if "slowest" means lowest capacity relative to the load it receives. It is misleading if it means slowest per request. A component with a long service time and plenty of parallel workers can have spare capacity. A component with a short service time and few workers can be saturated.

How do you calculate utilisation?

Utilisation, written ρ (rho), is the fraction of time a component is busy:

ρ = arrival rate × service time ÷ workers
  • Arrival rate (λ): requests per second that reach this component. Count only the requests that actually reach it: a database behind a cache sees only the misses.
  • Service time (S): how long one request occupies a worker, excluding time spent waiting in a queue.
  • Workers (c): how many requests it can serve at once: threads, processes, connections in a pool, CPU cores.

Capacity is workers ÷ service time. A pool of 8 database connections where each query takes 20 ms can serve 8 ÷ 0.020 = 400 queries a second. At 300 queries a second, utilisation is 300 ÷ 400 = 75%.

Brendan Gregg's USE method applies the same idea to running systems: "For every resource, check utilization, saturation, and errors." He defines utilisation as "the average time that the resource was busy servicing work" and notes that "100% utilization is usually a sign of a bottleneck".

Why does latency explode near 100% utilisation?

Requests rarely arrive evenly. When a burst lands on a busy component, the extra requests wait in a queue. The busier the component, the more often a request finds every worker occupied, and the longer the queue it joins.

For the simplest model, a single-server queue with random arrivals and service times (M/M/1), the average time in system is the service time divided by (1 − ρ). This follows from Little's Law and the M/M/1 queue length, as derived in these Emory University course notes. The multiplier is easy to work out:

Utilisation (ρ) Time in system ÷ service time
50% 2×
75% 4×
90% 10×
95% 20×
99% 100×
5×10×15×20×25×0%50%100%50%: 2×75%: 4×90%: 10×95%: 20×Utilisation (ρ)
Single-server (M/M/1) queue: average time in system divided by service time equals 1/(1−ρ). Derived from Little's Law and the M/M/1 queue length; the curve is cut at 25×.

Going from 50% to 75% busy doubles latency. Going from 90% to 95% doubles it again, with far less extra traffic. Researchers at Boston University describe this shape as a "hockey stick": waiting time grows roughly linearly with utilisation "until a certain threshold is reached", then rises at a much higher rate until utilisation reaches 100% (Boston University Decision Sciences Research Lab). They also note that where the knee sits depends on the number of servers, so components with many workers stay flat for longer, then turn more sharply.

Little's Law: the check that ties it together

Little's Law states that "the average number of items in a queuing system, denoted L, equals the average arrival rate of items to the system, λ, multiplied by the average waiting time of an item in the system, W." John Little, who proved it in 1961, wrote in his 50th-anniversary review that it "holds under remarkably general conditions" (Operations Research, 2011).

In practice it lets you check a design without a simulator. If a service receives 300 requests a second and each spends 24 ms inside it, then on average 300 × 0.024 ≈ 7 requests are inside at any moment. If that service only has 8 workers, it is nearly full, whatever its CPU graph says.

A worked example: which component is the bottleneck?

Take a read-heavy service at a peak of 2,000 requests a second. Every request goes through an API gateway and an app service and checks a Redis cache. 15% of requests miss the cache and query Postgres. 5% of requests also call an external payment API.

Component Arrival rate Service time Workers Capacity Utilisation
API gateway 2,000/s 2 ms 12 6,000/s 33%
App service 2,000/s 4 ms 16 4,000/s 50%
Redis cache 2,000/s 0.1 ms 1 10,000/s 20%
Postgres 300/s 20 ms 8 400/s 75%
Payment API 100/s 300 ms 200 667/s 15%

The payment API is by far the slowest component at 300 ms per call, and it is the least busy. The bottleneck is Postgres at 75%.

How bad is 75% for an 8-connection pool? Treating it as an M/M/c queue (random arrivals, 8 servers, 20 ms average service time), the Erlang C formula gives:

  • 36% of queries find all 8 connections busy and have to wait.
  • The average wait is 3.6 ms, so the average time per query is 23.6 ms.
  • By Little's Law, 300 × 0.0236 ≈ 7.1 queries are in Postgres on average: close to the pool size of 8.

These are the same M/M/c and Little's Law results used to check a queueing simulator against theory.

These are model numbers, not measurements. Real service times are not exponential, and real arrivals come in bursts, which usually makes queueing worse, not better.

What happens when the cache hit rate drops?

Now suppose a deploy changes a cache key and the hit rate falls. Nothing about the app service or gateway changes, but every lost cache hit becomes a Postgres query:

Cache hit rate Postgres load Utilisation Average time per query
85% 300/s 75% 23.6 ms
82.5% 350/s 87.5% 32.7 ms
81% 380/s 95% 62.2 ms
80.25% 395/s 98.8% 212 ms
80% 400/s 100% Unbounded

A five-point drop in hit rate takes Postgres from comfortable to saturated, and the average query time grows ninefold before the queue stops draining at all. The averages above also assume that clients wait patiently.

Real clients time out and retry. The Google SRE book names overload as "the most common cause of cascading failures" and warns that "the retries themselves may be keeping the backend in an overloaded mode" (Site Reliability Engineering, Addressing Cascading Failures). Retries at several layers multiply (what happens when a message queue fills up walks through it): in the book's example, "a single user action may create 64 attempts (4^3) on the database". AWS describes the same effect: retries multiply "the offered load on the system", and "throughput typically degrades when the system is overloaded" (Amazon Builders' Library, Using load shedding to avoid overload).

Why do p99 latencies matter more than averages?

Averages hide the requests that users notice. When one user request waits on many servers, the slowest of them sets the response time.

In "The Tail at Scale", Jeff Dean and Luiz André Barroso describe a server that usually responds in 10 ms but takes one second at the 99th percentile. One request in 100 to that server is slow. If a request must collect responses from 100 such servers in parallel, "63% of user requests will take more than one second" (Dean and Barroso, Communications of the ACM, 2013; passage quoted in The Morning Paper). The arithmetic is 1 − 0.99¹⁰⁰ ≈ 0.63.

0%50%100%0100200300100 servers: 63%Servers one request waits on
If each server is slow on 1% of calls, a request that waits for N servers is slow with probability 1 − 0.99N.

Feeds, search and anything else that gathers results from many shards have this shape; the news feed design is a worked example of fan-out. A component running at high utilisation does more damage than its average latency suggests. Its queue makes its tail slow, and every request that fans out to it inherits that tail.

How do you fix a bottleneck, and where does it move?

There are four kinds of fix, and each one changes a term in the utilisation formula:

  1. Reduce the work per request (lower service time). Add an index, cache a computed result, or remove a query.
  2. Add workers (raise capacity). Add replicas, threads, processes or connections, as long as the resource underneath them can serve them.
  3. Send it less traffic (lower arrival rate). Raise the cache hit rate, batch writes, or move work to an asynchronous queue. The URL shortener design shows how much a read cache takes off a database.
  4. Shed load when you cannot keep up. Reject the excess quickly so the requests you accept still finish. AWS recommends that a server near overload "should start rejecting excess requests so that it can focus on the requests it decides to let in". A distributed rate limiter is one way to do this at the edge.

In the example, suppose an index halves the Postgres query time from 20 ms to 10 ms. Capacity doubles to 800 queries a second, utilisation drops to 37.5%, and the average query time falls to about 10 ms, with almost no queueing.

The busiest component is now the app service at 50%. If traffic doubles to 4,000 requests a second, the app service reaches 100% while Postgres is back at 75%. The bottleneck has moved. As Microsoft's guide puts it, "alleviating one bottleneck can lead to the discovery of the next one."

Before, 2,000 req/sAfter index, 2,000 req/sAfter index, 4,000 req/sAPI gateway33%33%67%App service50%50%100%Redis cache20%20%40%Postgres75%37.5%75%Payment API15%15%30%100%
Utilisation (ρ = arrival rate × service time ÷ workers) for the worked example. Indexing the query moves the bottleneck from Postgres to the app service.

Adding workers is not free either. Neil Gunther's Universal Scalability Law models how contention and coordination between workers mean that throughput can stop growing, and beyond a point "becomes retrograde" as you add more (Gunther, A General Theory of Computational Scalability Based on Rational Functions, 2008). Doubling a connection pool does not double a database's capacity if the database is already short of CPU or locks.

How do you find the bottleneck in a real system?

The same steps work on a whiteboard and in production:

  1. Draw every component a request touches, including caches, pools and third-party APIs.
  2. Write down each component's arrival rate. Follow the traffic: cache hit rates, fan-out and retries all change how many requests reach the next hop.
  3. Measure or estimate each service time and worker count. In production, take them from metrics. In an interview, state your assumptions out loud.
  4. Compute utilisation for every component and rank them. The top one is your bottleneck. Treat anything around 75% or higher as a warning. In the single-server model above, 75% already means four times the service time. Components with many workers, like the 8-connection pool in the example, stay flat for longer, but they turn more sharply when they do.
  5. Check with Little's Law. In-flight requests should equal arrival rate × latency. If they don't, one of your numbers is wrong.
  6. Change one thing, then recompute. The bottleneck will move.

In production, Gregg's USE method gives you the same data from the other direction: check utilisation, saturation (queued work) and errors for every resource, and the bottleneck is the one with high utilisation and a growing queue. Useful saturation signals include time spent waiting for a connection from a pool, CPU run-queue length, lock waits in the database, and one shard or partition that is much busier than the rest.

To see these effects without building the system, you can model the same design in StackMonkey, a free browser-based system design simulator, by opening the URL shortener template, freezing the cache and watching which component's queue fills first. Its queueing engine is checked against M/M/c and Little's Law.

About this article

Written by the team that builds StackMonkey. The worked-example numbers were computed for this article and checked by a second reviewer against the formulas named below. If you find an error, email [email protected] and we will correct it and note the change here. More about the project is on the about page.

Sources

  • John D. C. Little, "Little's Law as Viewed on Its 50th Anniversary", Operations Research 59(3), 2011. Authorised reprint.
  • Jeffrey Dean and Luiz André Barroso, "The Tail at Scale", Communications of the ACM 56(2), 2013. Google Research.
  • Mike Ulrich, "Addressing Cascading Failures", in Site Reliability Engineering, O'Reilly, 2016. sre.google.
  • Brendan Gregg, "The USE Method". brendangregg.com.
  • David Yanacek, "Using load shedding to avoid overload", Amazon Builders' Library. builder.aws.com.
  • Maleyeff, Corlu and Lu, "Finding the Knee of a Waiting Line Hockey Stick Curve". Boston University.
  • Neil J. Gunther, "A General Theory of Computational Scalability Based on Rational Functions", 2008. arXiv:0808.1431.
  • Microsoft, "How to Investigate Bottlenecks". Microsoft Learn.

The worked-example figures were computed for this article with the M/M/1 and M/M/c (Erlang C) formulas, assuming Poisson arrivals and exponential service times.

Watch a cache outage reach the database

Open the URL shortener template, freeze Redis and see which component's queue fills first.