Opening

In this post

  1. 1. Three Numbers That All Get Called “Speed”
  2. 2. Fast Is About One Request; Scalable Is About Many
  3. 3. Where Requests Actually Wait
  4. 4. Why “Nearly Full” Is the Danger Zone
  5. 5. Little’s Law: How Many Requests Are in Flight
  6. 6. Averages Hide the Slow Requests
  7. 7. What to Do on Monday
  8. Sources

Article

Fundamentals

Scalable Is Not Fast: Latency, Throughput and the Queue in Between

Why a service that answers in milliseconds can still fall over at launch, and the three numbers and one formula that explain it.

Author
Lovenish Singh Panwar
Published
Reading time
9 min read
Start reading

Picture a launch you may recognise. An endpoint answers in 40 milliseconds on your laptop and in staging. On launch day, the same endpoint takes four seconds, then starts timing out. Nobody changed the code. What changed was how many people asked at once.

So if it was fast, why didn’t it scale? Because fast and scalable are different things. This post gives you three numbers to tell them apart, one picture of where requests wait, and one formula for sizing what you run.

1. Three Numbers That All Get Called “Speed”

When someone says a service is slow, they usually mean one of three things.

Latency is how long one request takes, from the moment it is sent to the moment the answer arrives.

Throughput is how many requests the service completes per second.

Capacity is the most throughput the service can sustain: its ceiling, set by whatever runs out first, such as workers, database connections, CPU, or a service you call. Latency starts climbing well before you reach it.

Picture a supermarket checkout. Latency is the time from joining the line to walking out of the shop. Throughput is how many customers leave per minute. Capacity is how many customers per minute the open tills can handle.

These get mixed up because they all feel like speed, but they have different fixes. If one request is slow even when nobody else is around, the work itself is expensive, and the fix is to make each request cheaper. If requests are quick when traffic is light but slow at peak, you are near capacity. Making each request cheaper still helps if the work is what holds the slot, because it raises the ceiling. But if the limit is fixed, such as a connection cap or a rate limit on a service you call, you need more room, or less load.

So the first question to ask about any “it’s slow” report is: slow for one request, or slow for many?

2. Fast Is About One Request; Scalable Is About Many

Fast describes one request on a quiet system. Scalable describes what happens to latency as more requests arrive.

Imagine two endpoints. Endpoint A answers in 10 ms but can work on only two requests at a time. Endpoint B takes 50 ms but can work on twenty at a time. On a quiet system, A is five times faster. Now look at capacity. A can finish at most 200 requests per second (two at a time, 10 ms each). B can finish 400 (twenty at a time, 50 ms each).

At 150 requests per second, A is 75% busy and B is under 40% busy. Push traffic to 190 per second and A is 95% busy, while B is still under half busy. Now A’s requests spend most of their time waiting in line: the average time per request climbs from 10 ms to about 100 ms, while B stays at about 50 ms. Why waiting climbs so fast near capacity gets its own section and chart below. Past 200 per second, A cannot keep up at all, and its line grows without limit.

The fast endpoint fails first. Speed is a property of one request. Scalability is a property of many, and it depends on capacity as much as on the time each request takes.

3. Where Requests Actually Wait

Every request’s latency splits into two parts:

time in system = waiting time + service time

Service time is the work itself: running your code, querying the database, building the response. Waiting time is everything before the work starts, spent in a line because every slot is busy.

On a quiet system, waiting is close to zero, so latency is roughly service time. That is why tests on a laptop look great. Under load, service time often stays about the same, but waiting grows. In the checkout picture, the cashier does not scan any slower at 5 p.m.; the line is just longer.

In a typical service, lines form in a few places:

  • The request queue in front of the server’s worker threads.
  • The database connection pool, when every connection is checked out.
  • Limits on calls to another service, such as a client with a fixed number of connections.
  • Locks, where requests take turns on shared data.

Each of these has a fixed number of slots. When the slots are full, the next request waits. Finding which one fills first is most of the work in diagnosing a scaling problem.

Two panels. In the first, a request goes into a service, with a bar beneath labelled latency, measured with the system idle. In the second, four requests arrive, wait in a queue, pass to three workers and leave; labels mark throughput, capacity, and the queue as where waiting grows as load rises.
Speed belongs to one request. Scalability belongs to many.

4. Why “Nearly Full” Is the Danger Zone

Utilization is how busy a resource is on average: arrival rate divided by capacity. For a pool, it is the average share of slots in use. A worker pool at 80% utilization has, on average, 80% of its workers busy.

You might expect waiting to grow in step with utilization. It does not. To see the real shape, use the simplest model in queueing theory, called M/M/1. The name is shorthand for three assumptions, one per position:

  • The first M is about arrivals. Requests arrive at random, independently of each other, at a steady average rate. When the last one arrived tells you nothing about when the next will. (M stands for “Markovian”, which here means memoryless.)
  • The second M is about the work. Each request’s service time is also random, with a fixed average and a wide spread: many requests are quick, and a few take much longer.
  • The 1 is the number of servers: one worker, handling one request at a time, while the rest wait in a single line.

No real service matches these assumptions exactly. The model is useful because it is simple: it gives a formula you can read at a glance. Under M/M/1, the average time a request spends in the system is:

time in system = service time ÷ (1 − utilization)

Say each request needs 10 ms of work. Then:

Utilization Average time in system
50% 20 ms
80% 50 ms
90% 100 ms
95% 200 ms

Going from 50% to 80% busy adds 30 ms. Going from 80% to 95% adds 150 ms. The last fifteen points of utilization quadruple the time.

Replace the 1 with k and you get M/M/k: the same model with k workers sharing one line. With more workers, requests wait less at the same utilization, but waiting still climbs steeply as the pool nears full. The figures for endpoints A and B earlier came from this version. At 95% busy, A’s two workers give about 100 ms, where a single worker would give the 200 ms in the table. B’s twenty workers, under half busy, give about 50 ms, with almost no wait.

Real systems are not exactly any of these models. Traffic comes in bursts and requests vary widely in size, and both change the exact numbers. What carries over is the shape: as a resource gets close to fully busy, waiting climbs steeply, and a small rise in traffic brings a large rise in latency.

That is the practical case for headroom: run your busiest resource well below the steep part. Where that is depends on your system. The shaded band in the chart is illustrative, not a rule for your system.

Line chart of time in system, 0 to 200 ms, against utilization, 0 to 100%. The line stays nearly flat until about 70%, then rises steeply. Marked points read 20 ms at 50%, 50 ms at 80%, 100 ms at 90% and 200 ms at 95%. The area from 70% upward is shaded as the steep region.
Illustrative M/M/1 curve with a 10 ms service time. Real systems give different numbers but the same steep rise near full.

5. Little’s Law: How Many Requests Are in Flight

One formula ties the three numbers together. Little’s Law says that, for a stable system over the long run:

L = λW

  • L is the average number of requests in the system, waiting or being served.
  • λ (lambda) is the average arrival rate, in requests per second.
  • W is the average time a request spends in the system, in seconds.

John Little published a proof in 1961. The law does not depend on the arrival pattern or the order in which requests are served. It needs the system to be stable over the long run: the averages settle, and what enters eventually leaves. It holds for whatever boundary you draw, a whole service or a single pool, as long as L, λ and W are measured for that same boundary.

Its everyday use is sizing. Draw the boundary around one pool, say the service’s workers. Suppose the endpoint receives 200 requests per second and each request holds a worker for a quarter of a second, not counting any time spent waiting for one:

Quantity Value
Arrival rate, λ 200 requests per second
Time each request holds a worker, W 0.25 seconds
Workers busy on average, L = λW 50

On average, 50 workers are busy. A pool of exactly 50 would run at 100% utilization, the far right of the curve above, where the queue in front of it grows without limit. So 50 is the floor, not the size. The pool needs to be comfortably bigger.

Two cautions. First, Little’s Law is about averages. Traffic peaks above its average, so size for the peak and add headroom on top. Second, use the right W. For a pool, W is how long a request holds a slot. For the whole service, W is the full response time, waiting included. When a queue builds, that W grows, and the number of requests in the service grows with it. That is the spiral you see in an overloaded service.

In a Java service, the numbers you are sizing are concrete settings: the server’s maximum worker threads and the maximum size of your database connection pool. Little’s Law tells you what those limits need to hold, using how long a request holds that resource, not its whole response time. Your measurements tell you λ and W.

6. Averages Hide the Slow Requests

An average can look healthy while a real share of users wait far longer. If 99 requests take 20 ms and one takes 2 seconds, the average is about 40 ms, which describes nobody’s experience.

Percentiles describe it better. The p50, or median, is the time half of requests beat. The p95 is the time 95% beat, and the p99 the time 99% beat. The p95 and p99 are your slow tail.

The tail matters more as systems grow. When one user action calls many servers and has to wait for all of them, the slowest reply sets the pace. Jeffrey Dean and Luiz André Barroso illustrate this in “The Tail at Scale” (2013): if each server is slow only 1% of the time, a request that waits on 100 of them is slow about 63% of the time. Rare slowness at each server becomes common for users.

So watch the tail as load rises. In real systems, bursts and a mix of quick and slow requests stretch the slowest requests far more than the typical one, so the p99 often degrades noticeably before the average looks alarming.

7. What to Do on Monday

Here is what I would do with one endpoint this week.

  1. Measure the three numbers. Record latency percentiles (p50, p95, p99), throughput, and the load at which latency starts to climb. That last one is your practical capacity.
  2. Find the queue. Check which pool or limit fills first: worker threads, database connections, calls to another service, or a lock.
  3. Keep headroom. Run that resource below the steep part of the curve, and size it for peaks with Little’s Law.
  4. Then choose the fix. Make each request cheaper, add capacity, or limit and shed load. Pick by which number is actually the problem.

So why did the 40 ms endpoint fall over on launch day? It was fast, not scalable. Its capacity ran out, a queue formed, and waiting, not work, filled the time.

Sources

  • Little, J. D. C. (1961). “A Proof for the Queuing Formula: L = λW.” Operations Research, 9(3), 383–387.
  • Harchol-Balter, M. (2013). Performance Modeling and Design of Computer Systems: Queueing Theory in Action. Cambridge University Press.
  • Dean, J., and Barroso, L. A. (2013). “The Tail at Scale.” Communications of the ACM, 56(2), 74–80.

Related posts

Get an email when a new post is out

Used only to email you when a new post is out. Held by Kit. Unsubscribe anytime. Privacy

All posts

↑ ↓ moveEnter openEsc closeTap a result to open it