By the Numbers / Queues

Queues by the Numbers

Systems don't fall over when they're full. They fall over when they're busy, and busy starts a lot earlier than you'd think.

This page works it out from a handful of formulas. Every chart puts the formula, in ink, next to a small simulation running in your browser, as terracotta dots, so you can watch where the math holds and where it quietly stops working.

2.25×More waiting at 90% busy than at 80%. Your 4-minute supermarket line becomes 9 minutes.
63%Requests that hit a slow server when they fan out to 100 servers that are each slow 1% of the time.
64×Database attempts from one click when 3 layers each try 4 times. A chain letter, forwarded three times.
24×Faster tail for Google's BigTable after sending backup requests at 10 ms: 1,800 ms down to 74 ms, for 2% more traffic (Dean and Barroso, 2013).
4.0×
ArrivalsServer

This is one checkout. Shoppers arrive at random and take a random time to serve, slowed down so you can watch. The scale under the slider is the average wait in service times. Drag past 90% and keep an eye on the line.

Little's Law: count what's inside

Here is a trick that works on almost anything with a line. Count how fast things arrive and how long each one stays. Multiply, and you know how many are inside.

L = λ · W

A supermarket that lets in two shoppers a minute, each staying fifteen minutes, holds thirty shoppers on average. You don't need to know the layout, how many tills are open or who is holding up the deli counter. A service handling 2,000 queries a second, each holding a database connection for 4 ms, keeps eight connections busy. Same arithmetic.

People leaned on this for decades before anyone proved it. John Little, the first doctoral student in operations research in the United States, was a young professor at the Case Institute of Technology in Cleveland when he published the proof in 1961. Until then it was a formula that kept turning up in specific queue models, with no general proof. He lived to 96.

Why it works. Draw every request as a bar from when it arrives to when it leaves, like the figure on the right. At any moment, the number of bars you cut through is how many are inside. Now add up the area of all the bars. You can sum it column by column (average number inside × time) or bar by bar (number of requests × average time each). It's the same area either way, so the two have to match.

The catch is that it only talks about averages. Multiply p99 latency by the request rate and you get nothing useful. Count only what actually got in: if you're shedding load, rejected requests never took up any room. And measure over a long window on a system that isn't growing. While a backlog is building, the formula describes the past, not what the next request will face. The agent preset shows this: 90-second tasks measured over a 48-second window don't add up.

You can draw the box anywhere. Around the waiting line alone, it gives you the average line length. Around the servers alone, it gives you how many are busy, which is utilization. That's the number the rest of this page is about.

8in flight on average

One sample path. Bars are requests: ink arrived inside the window, indigo were already in flight. Bottom: L(t).

L(t)time-average L, measuredλ × W, formula

Toy assumptions: Poisson arrivals, time in system lognormal with the mean W you set (coefficient of variation 1), unlimited concurrency. The identity does not care about any of these. The window holds about 40 arrivals so edge effects stay visible; when W is long compared with the window, the measured numbers drift apart, which is the window's fault, not the law's.

Why the line explodes near 100%

You've felt this at the supermarket. The store gets a little busier and the line gets a lot longer. That isn't bad luck. For one checkout with shoppers arriving at random, the average wait in line, counted in service times, is

Wq / τ = ρ / (1 − ρ)

where ρ (rho) is the share of time the cashier is busy. Try a few values. Half busy, you wait one service time. At 80%, four. At 90%, nine. At 99%, ninety-nine.

So the step from 80% to 90% more than doubles the wait. The last ten points of utilization cost more than the first eighty, which is why a database at 95% isn't efficient. It's one bad minute away from a very long line.

Randomness is the other ingredient. In 1961, the same year as Little's proof, John Kingman, a Cambridge mathematician just out of his undergraduate degree, showed how much it matters. (He went on to run the University of Bristol.) His approximation works for any pattern of arrivals and service:

Wq ≈ ρ/(1−ρ) · (ca² + cs²)/2 · τ

The two c² terms measure how uneven things are: the gaps between arrivals, and the time each job takes. Random is 1 and clockwork is 0. Because they multiply the utilization term, smoothing things out works like adding capacity. Split long queries from short ones, or spread out bursty clients, and the line shrinks as if you'd bought hardware. If everything were perfectly regular there would be no line at all, even at 99% busy. Nothing real works that way, but it tells you where the waiting comes from.

One thing never changes: going from 80% to 90% still multiplies the wait by 2.25, however uneven things are. Variability moves the whole curve up or down. It doesn't change the shape.

Where Kingman's formula stops working

It's built for busy systems. It is exact for the fully random case, and whenever arrivals are random it matches the exact Pollaczek–Khinchine result. With non-random arrivals at moderate load it can be well off: set ca² to 0 or 4 at 50% and compare the dots with the curve. It also only gives you the average. Near saturation the wait is roughly exponential with that average, so p99 is about 4.6 times the mean there heavy traffic only.

4.0τmean wait in queue, Kingman

Mean wait in queue, in service times, against utilization

KingmanM/M/1 referencesimulated, ±2 s.e.

Toy assumptions: one first-come-first-served server, mean service time 1, gaps and service times drawn from gamma distributions with the chosen c² (0 means constant). Each dot averages 150,000 to 400,000 simulated customers after a 10% warm-up. Error bars come from 20 batch means; they are wide near saturation because the queue has a long memory there.

One shared line beats many short ones

Ever notice that the other line always moves faster? With three checkouts, it usually does. The chance that yours is the fastest is only one in three.

Airport security gets around this with one long snake feeding every lane. It looks worse and works far better. With 8 lanes, 80% busy and a minute per traveler, the shared snake averages about 17 seconds of waiting. Eight separate lines average four minutes, fourteen times longer, because with one line no lane sits idle while people are stuck behind a slow traveler next door.

The math behind this comes from Copenhagen. In 1908 the Copenhagen Telephone Company hired a schoolteacher named Agner Krarup Erlang. Its chief engineer, Johan Jensen (the Jensen of Jensen's inequality), had met him through the Danish mathematical society, and he put Erlang in charge of a new lab. By 1909 Erlang had shown that phone calls arrive at random in exactly the sense this page uses. By 1917 he had formulas for how many lines and operators an exchange needed, which is the same question as how many database connections your service needs.

Wq = C(c, a) / (cμ − λ)

Here c is the number of servers, a is how many are busy on average (Little's Law again) and C is Erlang's formula for the chance you have to wait at all. Bigger pools can also run hotter for the same wait, which is why huge call centers look so efficient.

Where Erlang's formula comes from, without the matrix. Think of the number of people in the system as a row of states: 0, 1, 2 and so on. Each state leaks to the next one up at the arrival rate and to the next one down at the rate the busy servers finish. Textbooks find the steady state as an eigenvector of a big matrix, but you don't need one. Picture a row of water tanks joined by pipes. Once things settle, each pipe carries the same flow both ways, so each tank's level is the one before it times a simple ratio. Fill them left to right, scale so the water adds up to 1, and Erlang's C is the share sitting in tanks c and above.

Software builds separate lines by accident all the time: a connection pool per pod, a worker pool per shard, sticky routing, a thread pool per tenant. The fixes are a shared dispatcher, sending each job to the shortest line, or checking two lines at random and picking the shorter. A shared line has one requirement. The work has to be interchangeable, or one slow kind of job blocks everyone behind it.

Sizing a connection pool

A connection pool is Erlang's telephone exchange with connections instead of operators. Hold time is everything between checking a connection out and handing it back: the query, the network round trips and any application code that runs inside the transaction. Little's Law gives you the floor (rate × hold time), and Erlang adds the headroom so checkouts rarely wait.

The ceiling usually comes from a rule of thumb on the PostgreSQL wiki that HikariCP's docs made famous: (core_count × 2) + effective_spindle_count. It's easy to misuse. It counts connections on the database server across every app instance, so 20 pods with pools of 10 are already asking for 200. It means physical cores, not hyperthreads. The spindle part dates from spinning disks, and HikariCP's own page says nobody has worked out how it holds on SSDs. It also ignores time a connection sits idle while your app thinks, which raises the floor without raising the ceiling. Use it as a place to start benchmarking, not as an answer.

If the floor ends up above the ceiling, a bigger pool won't save you. It just moves the line out of the pool, where it's cheap and you can see it, into the database, where it turns into lock and CPU contention. Shorten the hold time or get a bigger database. The Postgres page covers what each connection costs the server in its Connections section.

One more sizing rule: pool deadlock

If one thread can hold several connections at once, the pool needs at least Tn × (Cm − 1) + 1 of them, where Tn is the number of threads and Cm is the most connections one thread holds at the same time. Any fewer and every thread can end up holding some connections while it waits for one more.

One shared line or many separate ones

14×longer average wait with separate lines

Mean wait in service times (log scale) against utilization

shared, Erlang Cseparate, one M/M/1 eachsimulated

Formula on top, simulated underneath. Toy assumptions: Poisson arrivals, exponential service with mean τ, first come first served. Separate lines each get a random share of arrivals, like random load balancing over per-pod pools. 100,000 simulated customers each.

Pool sizing: floor and ceiling

Floor: Erlang C, treating connections as servers with exponential hold times, smallest pool meeting the p99 checkout target. Per-instance pools assume even load balancing and at least one connection per instance. Ceiling: (2 × cores) + spindles, the PostgreSQL wiki starting point. Both are toy models; benchmark around them.

Fan-out turns rare slowness into the normal case

Drive across town through 100 traffic lights, each red only 1% of the time. You'll still stop at least once on 63% of trips. A request that has to hear back from 100 servers makes the same drive.

P(at least one slow) = 1 − (1 − p)n

The 63% isn't a quirk of these particular numbers. Whenever the fan-out is the inverse of the slow rate (100 servers at 1%, or 1,000 at 0.1%), the answer settles near 1 − 1/e, about 63%.

In February 2013 two senior Google engineers, Jeff Dean and Luiz André Barroso, wrote this up as "The Tail at Scale." Their point was that a big system can't get rid of slowness any more than a city can get rid of red lights, so it has to be built to live with it. They described a few ways:

  • Hedged requests. Send a backup copy after a short delay and take whichever answer arrives first. In their BigTable test, reading 1,000 keys spread over 100 servers, hedging after 10 ms cut the p99.9 from 1,800 ms to 74 ms for about 2% more requests.
  • Tied requests. Queue the request on two servers at once; whichever starts first tells the other to drop it. On a mostly idle cluster the median fell 16% and the p99.9 nearly 40%.
  • Micro-partitions and canaries. Use many more partitions than machines, so load can move in small pieces, and try a request on one or two servers before sending it to all of them.

All of this assumes slowness comes from the server, not the request. A backup request rescues a server that's paused for garbage collection or stuck next to a noisy neighbor. It does nothing for a query that's simply expensive, because that query is slow on every copy. Hedge it and you double the load at the worst possible moment. Move the last slider to watch the formula and the simulation split apart. Hedges are extra traffic too, so cap them (gRPC's retry throttling covers hedges) and cancel the loser.

63%of requests hit a slow server

Share of requests touching at least one slow shard, against fan-out (shards, log scale)

no hedgingwith hedging, independent slownesssimulated

Formula on top, simulated underneath. Toy assumptions: a normal shard answers in about 5 ms (lognormal, σ = 0.4); a slow one takes 0.5 to 1.5 s, echoing the paper's one-second example. Request latency is the slowest shard. A hedge goes to an independent replica; with "caused by the request" above 0, that share of slow shards are slow on the replica too. Formula columns assume independence. Simulation: up to 5,000 requests.

Why more workers can make things slower

In 1967 IBM's Gene Amdahl made an argument that still ends design meetings. If part of a job has to run one step at a time, no amount of parallel hardware gets you past it. Picture a kitchen where every plate passes one inspector. Hire more cooks and the inspector becomes the restaurant's speed limit.

Amdahl's curve flattens out, but it never goes down, and real systems do go down. Neil Gunther, a performance analyst, ran into this while modeling tightly coupled Unix multiprocessors and added a second cost: keeping everyone in sync. Think of a team where everyone has to talk to everyone. Ten people means 45 conversations; twenty means 190. He set it out in full in his 2007 book Guerrilla Capacity Planning as the Universal Scalability Law:

X(N) = λN / (1 + σ(N−1) + κN(N−1))

σ (sigma) is contention: waiting for something shared, like a lock, a hot row or a single writer. κ (kappa) is the cost of staying in sync: cache lines bouncing between cores, locks changing hands, nodes invalidating each other's copies. If κ is above zero at all, the curve has a peak at N* = √((1 − σ)/κ). Past that point, adding workers lowers throughput. The PostgreSQL wiki describes this exact shape for database connections, a climb, a knee and then a fall, and it's the other reason the pool ceiling above exists.

You can fit the law to a handful of load-test results. Rearranged, it becomes a simple quadratic, N/X(N) = (1/λ)(1 + σ(N−1) + κN(N−1)), so an ordinary least-squares fit gives you λ, σ and κ. Paste your own numbers into the tool.

Least squares, in plain terms. Each measured point pulls the curve toward itself. The fit picks the three knob settings that make the total squared miss as small as possible. At that setting, nudging any one knob no longer helps, which gives you three balance conditions, one per knob. Three equations, three unknowns, solved like a simultaneous-equations problem from school.

Be careful with the fit. If your data stops before the knee, κ and the peak are guesses, and the tool will say so. Fitting it this way gives the low-N points extra weight. A negative σ means things got better than linear, usually because caches warmed up. And the law describes rather than diagnoses: it tells you there's a syncing cost, not where it lives.

N* ≈ 32peak concurrency

Throughput against concurrency

measuredUSL fitAmdahl fit (κ = 0)

The preset datasets are synthetic samples generated from known σ and κ plus 3% noise, so you can check how well the fit recovers them. Paste your own load-test results to replace them.

Overload: when retries keep a system down

Here's the strangest failure on this page. A server can be 100% busy and 0% useful.

It goes like this. Something knocks the system over for a moment: a traffic spike, or a few seconds of lost capacity. Requests start timing out, so clients retry. The server still finishes the abandoned originals, which means it spends all its time on work nobody is waiting for, while the retries keep the line full. Then the trigger goes away and the system stays down. Nathan Bronson and three colleagues named this a metastable failure at HotOS in 2021. A year later, Lexiang Huang and colleagues took apart 22 of them across 11 organizations, and cited AWS's outage of 7 December 2021 as a fresh case. The simulation on the right fails the same way, and you can try the fixes on it.

Retries also multiply on the way down the stack, like a chain letter. If each of d layers tries r + 1 times, one click can turn into (r + 1)d attempts at the bottom. Google's SRE book counts 64 database attempts for three layers that each try four times. AWS's Builders' Library counts 243 for five layers that each try three times. Retries are great for one-off glitches. They're poison during overload, because they add load at the exact moment there's none to spare.

The fixes the industry has settled on over the last fifteen years:

  • Retry budgets. Limit retries as a share of all traffic, not per request. gRPC stops retrying (and hedging) once too many recent calls have failed, and AWS SDKs have used a token bucket for retries since 2016.
  • Drop expired work. Pass deadlines along so a server can skip requests whose client has already given up.
  • Controlled delay. Facebook's version of CoDel: once the line hasn't been empty for 100 ms, anything that has waited more than 5 ms gets dropped. Those numbers worked across a wide range of their services, and CoDel itself (Nichols and Jacobson, 2012) uses the same 5 ms and 100 ms for network routers.
  • Adaptive LIFO. Serve the newest request first once a backlog forms, since the oldest ones have probably timed out. In the simulation it brings goodput back fast but leaves thousands of stale requests sitting in the line. Pair it with controlled delay and watch the peak queue drop.
  • Small queues. The SRE book suggests queues no bigger than half the thread pool, and notes that Gmail often runs servers with no queue at all.
  • Adaptive concurrency limits. Netflix in 2018 and Uber's Cinnamon in 2023 borrow an idea from TCP Vegas: watch latency and let it tell you how many requests to have in flight.
  • Backpressure. Tell callers to slow down instead of buffering their work: bounded channels, consumers that pull, a 429 with Retry-After.

Retry amplification

64×attempts at the bottom layer

Worst case, when every attempt fails. The budget line assumes each layer caps retries at 10% of its traffic, a common style of budget; check your own library's rule.

A metastable failure, simulated

0%

Requests per second over a 40 s run. Shaded: the capacity dip.

goodput, simulated (answered before timeout)attempts offeredcapacity

Toy assumptions: one server, 1,000 requests/s capacity (exponential service, 1 ms mean), Poisson users, a retry 0 to 20 ms after a timeout or a fast rejection. The server finishes abandoned requests unless "Drop expired" is on. Retry budget: 0.1 token per new request, bucket of 10. Controlled delay: once the queue has been non-empty for 100 ms, shed anything that waited over 5 ms. The dip starts at 8 s.

Bursts: same average, much longer line

An airport checkpoint that screens 600 people an hour has an easy morning when they trickle in and an awful one when four tour buses pull up at once. Same number of people. The difference is how they arrive, and most capacity plans assume the gentle version: random, independent arrivals, which the textbooks call Poisson.

Agent workloads are tour buses by design framing. One planning step fires off a batch of tool calls, lookups or queries within a few milliseconds, then goes quiet while the model thinks. Real LLM traffic already looks lumpy. BurstGPT, built from 10.31 million requests to Azure OpenAI services over 213 days, traced memory-related failures in serving systems back to short bursts. ServeGen (2025) found that the Poisson model often fits poorly.

The simplest tour bus is a batch of b requests arriving together, with the batches themselves arriving at random. The average rate and utilization don't change. The exact average wait does:

Wq / τ = ρ(b+1) / (2(1−ρ)) + (b−1)/2

At 70% busy, batches of eight wait 14 service times on average, six times what a Poisson plan predicts. Some of that you pay even on an idle server, because the last person off the bus waits for the seven ahead. That part comes from the burst, not the load, so no amount of spare capacity removes it. Shaping does: add jitter, cap how many calls each agent can have in flight, or give each agent a token bucket.

Where the formula comes from, and what it leaves out

Treat each bus as one big job whose size is the sum of b service times, apply the Pollaczek–Khinchine formula to the buses, then add the average wait behind your own busmates, (b−1)/2 service times. Set b = 1 and you get back the ordinary single-checkout result.

Real bursts vary in size and spread out over a few milliseconds, so identical, simultaneous batches are the pessimistic simple case. Bursts that line up across agents (the same schedule, prompt template or upstream event) are worse than independent ones, and no single-queue formula sees that. LLM calls also vary enormously in how long they take, because output length varies, which raises cs² on top.

6.0×the wait a Poisson plan predicts

The same mean rate, two ways

Mean wait in queue, in service times, against utilization

batches, exactPoisson reference (M/M/1)simulated

Toy assumptions: one first-come-first-served server, exponential service with mean τ, batches of exactly b arriving together, batch arrivals Poisson. 150,000 simulated requests per dot.

Practice: guess first, then run it

Queue math is easy to underestimate, so check your gut. Commit to a number first. The reveal runs the formula and a fresh simulation side by side.

One server, Poisson arrivals, exponential service with a 10 ms mean. Response time is wait plus service; in this model it is exponential with mean τ/(1−ρ), so its p99 is ln(100) ≈ 4.6 times that mean. Simulation: 1,000,000 requests.

Worst case: the database is down, so every attempt at every layer fails and every layer spends its full retry allowance on each call it receives.

What the last fifteen years taught us

Utilization targets are variability targets

"Run at 70%" means nothing without c². Smoothing arrivals and separating work classes is capacity you get without buying hardware.

Design for the tail, then the fan-out

Every fan-out multiplies the chance of meeting a p99. Budget latency per hop from the end-to-end percentile, and hedge only server-caused slowness.

Bound everything

Queues, retries, in-flight requests and pools all need explicit limits. An unbounded queue is a latency bomb with a delayed fuse.

Retries are load

Budget them globally, add jitter, and retry at one layer only. Per-request retry counts multiply across layers.

Overload is a state, not a level

Metastable systems stay broken after the trigger is gone. Test recovery from a dip, not just peak throughput, and shed or drop stale work.

Static limits rot

Capacity changes with every deploy, cache state and neighbour. Limits that track latency have replaced hand-tuned constants at Netflix and Uber.

Timeline

  1. 2012

    CoDelNichols and Jacobson control queue delay rather than queue length; published as RFC 8289 (Experimental) in 2018.

  2. 2013

    The Tail at ScaleDean and Barroso make tail tolerance a design goal: hedged and tied requests, micro-partitions.

  3. 2015

    Fail at Scale; backoff with jitterFacebook publishes controlled delay, adaptive LIFO and client concurrency caps. AWS shows jitter cuts contention from synchronized retries.

  4. 2016

    SRE book; SDK retry bucketsGoogle's cascading-failures chapter: retry budgets, 64× amplification, small queues. AWS SDKs gain token-bucket retry limits.

  5. 2017

    gRPC retry designRetry and hedging policies ship with built-in throttling.

  6. 2018

    Adaptive concurrency limitsNetflix open-sources limits derived from TCP congestion control.

  7. 2021

    Metastable failuresBronson and colleagues name the pattern and its sustaining effects.

  8. 2022

    Metastable failures in the wild22 incidents across 11 organizations, written as AWS's December 2021 outage unfolded.

  9. 2023

    CinnamonUber runs TCP-Vegas-style adaptive concurrency across a wide range of services.

  10. 2024 to 2025

    LLM traffic is burstyBurstGPT and ServeGen trace production LLM serving and find arrivals that Poisson models poorly.

Open questions

What arrival model fits agents?

One decision spawns a tree of calls with heavy-tailed service times. Batch-Poisson is a first cut; there is no standard model yet open.

Predicting metastability

Bronson and colleagues called a systematic defence against unknown metastable failures an open problem. A 2026 preprint offers a causal characterization and a prediction methodology; whether it becomes tooling is open.

Admission control for unequal work

CoDel-style control assumes requests of similar cost. LLM calls and analytical queries differ by orders of magnitude, so delay alone is a weak signal framing.

Many small pools

A database or branch per agent means many small separate pools: the expensive configuration from the many-servers section, multiplied. Shared poolers help only if the work is interchangeable framing.

Autoscaling versus the hockey stick

Near ρ = 1 queues build in seconds while scale-out takes minutes. How much headroom a given scale-out lag requires is still answered by load tests rather than formulas framing.

Further reading

Mor Harchol-Balter, Performance Modeling and Design of Computer Systems: Queueing Theory in Action (Cambridge University Press, 2013). The book that brings queueing theory back to computer science. It is organized around puzzles a systems designer actually faces, such as one fast machine or n slow ones, and its exercises are where the counterintuitive lessons live.

Neil J. Gunther, Guerrilla Capacity Planning (Springer, 2007). The full presentation of the Universal Scalability Law, written for people who plan capacity three months ahead with whatever data they have. Read chapters 4 to 6 before fitting your own load tests.

Betsy Beyer, Chris Jones, Jennifer Petoff and Niall Richard Murphy (eds.), Site Reliability Engineering (O'Reilly, 2016). Chapter 22, on cascading failures, is the clearest practitioner account of retry budgets, queue sizing and load shedding, and it is free to read online.

Leonard Kleinrock, Queueing Systems, Volume 1: Theory (Wiley, 1975). The classic graduate text from UCLA, with birth-death chains, M/G/1 and G/G/1 worked through step by step. Dense, but the classic M/M/c and M/G/1 results on this page are derived in it.

Sources

Every simulation runs in your browser with a fixed random seed, so the same settings give the same dots. Interpretive or uncertain claims carry a flag.

MusicChordsRhythmBluesJazz HarmonySynthesisMIDIVoiceSoftwarePostgresInfrastructureThe GridData CentersEarthHurricanesEarthquakesStartupsFounder Equity