Course contents

15. Performance Engineering Lesson 2 of 8

Bottleneck Identification

Find the stage that limits throughput from utilisation and queue depth, see why scaling the wrong tier fails, and watch the bottleneck move after a fix.

16 minAdvanced9 steps
Loading the interactive simulation…
Loading the knowledge check…

Summary

  • End-to-end throughput is capped by the stage with the least capacity.
  • A plateau in throughput below the offered load means some stage is saturated.
  • Blocked callers look busy too: the bottleneck is the deepest stage saturated with its own work and with a queue in front of it.
  • Capacity added anywhere else is wasted; fixing the bottleneck promotes the next-smallest stage.
  • Break metrics down per instance, shard and endpoint: averages hide bottlenecks.
Deep diveHow it works, trade-offs, failure modes, misconceptions and the interview angle.

What it is

A bottleneck is the resource that limits a system's throughput: the stage with the least capacity relative to the load it receives. Every request-serving system has one at any given load. Bottleneck identification is the practice of finding it from measurements, rather than from intuition or from whichever dashboard is reddest.

Why it exists

Effort spent on a non-bottleneck stage changes nothing: more app servers in front of a saturated database add cost, not throughput, and can make latency worse. Meanwhile the symptoms of a bottleneck appear everywhere upstream of it, because callers wait for it. Without a method, teams scale the tier that looks busiest, which is often the wrong one.

How it works

Capacities per stage. For each stage estimate the maximum rate: concurrency ÷ time held per request. An app instance with 8 workers holding each for 69 ms does about 116 req/s; a database running 4 queries at 25 ms does about 160 queries/s. If every request visits each stage once, the smallest number is the system's ceiling. If some stages are visited several times per request (N queries per page) or only by some requests (cache misses), multiply by the visit ratio.

Symptoms of saturation. When the offered load exceeds the bottleneck's capacity:

  • throughput plateaus at the bottleneck's capacity, below the offered load;
  • the bottleneck runs at ~100% utilisation and has a queue in front of it (waiting threads, a full connection pool, consumer lag, run-queue length);
  • latency rises for every request that passes through it.

Propagation upstream. If callers block while waiting (a thread per request, a synchronous call), the waiting holds their resources too. Upstream stages then show high utilisation, full queues and often the errors (rejections, timeouts), even though their own work is light. The lesson shows exactly this: the app tier rejects every failed request while the database is the cause. Rule of thumb: the bottleneck is the deepest stage that is saturated with its own work and has requests waiting for it. Measuring where request time goes (traces with spans per dependency, pool wait time, queue wait time) confirms it.

Fixing it. Three options: make each request cheaper at the bottleneck (an index, fewer queries, smaller payloads), give the bottleneck more parallel capacity (bigger instance, more replicas or shards, more consumers), or send it less work (caching, batching, moving work off the critical path). Then re-measure: the next-smallest stage is now the limit, and the right fix there may be the one that was wrong a minute ago.

Hidden bottlenecks. Averages over a tier conceal a single slow member: a degraded host, a hot shard, a hot key, one expensive endpoint. Per-instance and per-endpoint breakdowns and tail latency (P99) reveal them.

The USE method. For each resource (CPU, memory, disk, network, thread pools, connection pools, locks, queues), check Utilisation, Saturation (queued work) and Errors. It is a checklist that keeps you from stopping at the first red graph. For request-level services, the complementary RED method tracks Rate, Errors and Duration per service.

When to use it

  • When throughput stops growing with load, or latency rises with load.
  • Before scaling anything: confirm the tier you are about to scale is the bottleneck.
  • During incidents, to decide which mitigation will actually relieve pressure.
  • In capacity planning, to know which tier binds first as traffic grows.

When not to

  • When the problem is not throughput: a functional bug, a misconfiguration or a single slow request path at low load needs debugging or profiling, not capacity analysis.
  • At very low utilisation everywhere, latency is dominated by the work itself (network hops, query plans), not by a saturated stage; optimise the critical path instead.

Trade-offs

Fix You gain You pay
Make the bottleneck's work cheaper (indexes, query tuning) Capacity and latency, often for free Engineering time; may need schema or code changes
Scale the bottleneck up or out Quick capacity Cost; stateful tiers (databases) scale out with difficulty
Cache in front of the bottleneck Large reduction in load for read-heavy traffic Staleness, invalidation, a new failure mode
Move work off the critical path (queues, async) Lower latency, levelled load Eventual consistency, operational complexity
Limit load (rate limits, shedding) Protects the bottleneck Some requests are refused

Alternatives

  • Profiling finds bottlenecks inside one process (a hot function, lock contention, GC).
  • Distributed tracing shows where time goes across services for individual requests, which is often faster than reasoning from utilisation alone.
  • Load testing with stepwise increasing load finds the knee and the first stage to saturate before production does.

Failure modes

  • Scaling the busiest-looking tier: the busy tier was blocked on a downstream one.
  • Trusting error sources: errors are raised where a queue overflows or a timeout fires, which is often upstream of the bottleneck.
  • Fleet averages: one saturated instance or shard hides behind a reassuring average.
  • Fixing once: after the fix, the next bottleneck appears, sometimes in a tier nobody was watching.
  • Making it worse: more callers against a saturated database means longer waits, more timeouts and retries, and possibly lower throughput through contention.

In production

Instrument queue and wait times, not just utilisation: thread pool queue length, connection pool wait time, consumer lag, CPU run queue. Use traces with spans for each dependency. Dashboards should show per-instance and per-shard breakdowns and P99, not only fleet averages. Write down each tier's measured capacity next to its current peak, so the binding tier is visible before it binds. Load test after major changes, because the bottleneck may move.

Common misconceptions

  • "The component throwing errors is the problem." It is the one whose queue or timeout overflowed first, often upstream of the cause.
  • "High utilisation means bottleneck." Blocked threads count as busy. Look for saturation with its own work and a queue in front.
  • "Adding servers always adds throughput." Only at the bottleneck.
  • "Once fixed, it stays fixed." Fixing a bottleneck promotes the next one.

Interview angle

In a design interview, state where you expect the first bottleneck at the target load (usually the database or a shared dependency), with numbers, and how you would confirm it (utilisation and saturation per tier, traces). When asked "what if traffic grows 10×?", walk the stages in order: which saturates first, what you do about it, and which one is next. Mentioning that blocked callers make upstream tiers look saturated shows real operational experience.

Model assumptions

The simulation is a simplified model, not a benchmark. Each app instance has 8 workers, 40 ms of its own work per request (lognormal, cv 0.4) and queues up to 30 requests before rejecting; a worker stays held while it waits for the database (blocking calls). The database runs 4 queries at once at 25 ms per read (10 ms after the index) and 40 ms per write, cv 0.4, and fails a query that waits more than 400 ms for a connection. Arrivals are Poisson; the balancer uses round robin; network hops take 1–10 ms. The slow instance is modelled as 3× longer service time. Utilisation is the busy fraction of workers or connections, not CPU. Numbers are illustrative.

The lesson as textEvery step of the simulation, written out.
  1. 1. A request passes through stages, each with its own limit

    Every request crosses a balancer, one of two app instances, and the database. Each stage has its own capacity. An app instance has 8 workers and holds one for about 69 ms per request (40 ms of its own work plus the database call): about 116 requests per second each, 232 for both. The database runs 4 queries at once at about 25 ms each: about 160 per second.

    At 100 requests per second every stage has room. Look at the two things that will tell you where the limit is: each stage’s utilisation and its queue (the number under each node).

    Scene: Users send 100 requests per second through a load balancer to two app instances, which each query one database. All stages have spare capacity and nothing fails.

    Key idea: End-to-end throughput can never exceed the capacity of the smallest stage. Write each stage’s capacity down.

  2. 2. Traffic doubles: something saturates

    One second in, traffic rises to 200 requests per second. Throughput does not follow: it stalls near 160, latency climbs and errors appear.

    Now look at the stages. The database shows 4/4 connections and a line of waiting queries. But the app instances look worse: 100% busy, with full queues, and they are the ones rejecting requests (503). Every error comes from the app tier. Two stages are red, and the errors point at the wrong one. Which is the bottleneck?

    Scene: At 200 requests per second throughput stalls near 160. The database has all 4 connections busy and queries waiting. The app instances are also fully busy with full queues, and they reject the excess requests.

    Key idea: Throughput plateauing below the offered load means some stage is at capacity. Utilisation and errors alone may point at the wrong suspect.

  3. 3. Busy waiting is not the bottleneck

    Follow one request. An app worker does its 40 ms of work, then calls the database and waits: for a free connection, then for the query. Measured per request, the database call now takes longer than the app’s own work. App workers are “busy” mostly doing nothing.

    That is how a bottleneck spreads upstream: the saturated stage’s queue holds callers’ resources (threads, connections, memory), so everything in front of it looks overloaded too. The real bottleneck is the furthest downstream stage that is saturated with its own work and has a queue in front of it. Here: the database.

    Scene: Same load. The database call, including the wait for a connection, takes longer than the app’s own work; app workers are mostly blocked waiting. The database is highlighted as the bottleneck.

    Key idea: Saturation propagates upstream through blocked callers. Find the deepest stage at 100% doing its own work, with requests waiting for it.

  4. 4. Scaling the app tier changes nothing

    The obvious reaction to red app servers is to add more. Two more instances join, doubling app capacity to about 464 requests per second.

    Throughput stays near 160. The database still runs 4 queries at a time; now twice as many blocked workers wait in its line, so latency roughly doubles, and the app tier keeps rejecting. Capacity added anywhere except the bottleneck is wasted, and here it adds load to the stage that is already full.

    Scene: Two more app instances are added. Throughput stays near 160 requests per second because the database is still saturated; more queries wait for it, latency roughly doubles and errors continue.

    Key idea: Adding capacity to a non-bottleneck stage does not raise throughput; it often just moves more waiting to the real bottleneck.

  5. 5. Fix the bottleneck itself

    Instead, make the database cheaper per request. The slow query gets an index: 25 ms → 10 ms, so the same 4 connections now handle about 400 queries per second. The two extra app instances go away again; they were not helping.

    Throughput rises to the full 200, errors stop, and latency drops for every request: the app workers stop waiting, so the app tier looks healthy again too, with the same two instances that “needed” scaling a minute ago.

    Scene: The database query is made faster with an index. With two app instances, all 200 requests per second complete, errors stop and latency drops; neither tier is saturated.

    Key idea: Spend effort on the bottleneck: make it do less per request, or give it more parallel capacity. Upstream symptoms disappear with it.

  6. 6. The bottleneck moves

    Traffic keeps growing, to 280 requests per second. The database is fine now (about 70% busy, only brief waits). But each app instance holds a worker for about 54 ms per request, so two of them top out near 296 per second.

    The app instances are now saturated with their own work, with queues in front of them, while the stage behind them has headroom. The bottleneck has moved upstream. This time adding app instances is the right answer.

    Scene: At 280 requests per second the two app instances are saturated with their own work and requests queue in front of them, while the database is about 70% busy with headroom.

    Key idea: Fixing a bottleneck promotes the next-smallest stage. Re-measure after every fix.

  7. 7. Now scaling the app tier works

    A third app instance raises the app tier to about 444 requests per second. Queues drain, all 280 per second complete, and P95 falls.

    Same action as the wrong fix earlier, opposite result, because this time the measurements pointed at the app tier: saturated with real work, a queue in front, and an idle-ish stage behind.

    Scene: With a third app instance all 280 requests per second complete; the app tier and the database both have headroom.

    Key idea: The right fix depends on where the bottleneck is now, not where it was last time.

  8. 8. A bottleneck can be a single instance

    App 2 lands on a noisy host and becomes 3× slower at its own work. Round robin still gives it a third of the traffic, more than it can now handle: App 2 saturates and rejects, while App 1 and App 3 stay around half busy.

    The fleet’s average utilisation looks unremarkable, but the tail latency and the errors all come from one box. Break metrics down per instance (and per endpoint, per shard) before concluding a tier is fine.

    Scene: App 2 is three times slower. It is saturated and rejects requests while App 1 and App 3 stay about half busy; P99 rises and errors appear.

    Key idea: Averages hide bottlenecks. Look per instance, per shard and at tail latency.

  9. 9. How to find the bottleneck

    App 2 is healthy again. The method: write down each stage’s capacity; when throughput plateaus, check utilisation and queue depth per stage and per instance; discount stages that are busy only because they are waiting on something downstream; the bottleneck is the stage saturated with its own work with a queue in front of it.

    Then fix that stage (less work per request, more parallelism, or less traffic to it via caching), and measure again: the bottleneck moves. This is the USE method in short: Utilisation, Saturation, Errors for every resource.

    Scene: Three healthy app instances and an indexed database handle 280 requests per second with headroom on every stage.

    Key idea: Measure per stage, follow the waiting downstream, fix the deepest saturated stage, re-measure.