Little's Law
One equation
Section titled “One equation”Picture a shop. Two customers walk in every minute, and each spends five minutes inside. How many are in the shop at any moment? Two a minute, each staying five minutes: 10. Nobody needed to know who arrives when. The answer follows from the two rates.
That is Little’s Law:
L = λ × W
- L is the average number of requests in the system at once, waiting or being served.
- λ (lambda) is the average rate at which requests arrive. For a system that is keeping up, it is also the throughput.
- W is the average time a request spends in the system, from arriving to leaving.
Mental model. The number of requests inside a system equals the rate they arrive times how long each one stays. If you know two of the three, you know the third.
The units have to agree. At 100 requests per second and 21.7 ms in the system, that is 100 × 0.0217 = 2.17 requests in the system on average.
Why it is so widely used
Section titled “Why it is so widely used”Little’s own article for the law’s fiftieth anniversary says it holds under remarkably general conditions. It does not depend on how arrivals are spread in time, or on the order in which requests are served. It applies to a single queue, to a network of them and to a part of a network. Over a period you have measured it is an accounting identity: the number inside, averaged over time, equals the arrival rate times the average time each request stayed. The care to take is to measure all three over the same period, and in practice to make the period long compared with the time a request stays, so that the requests still inside at its start and end do not skew the result.
That generality is why it appears everywhere in capacity work. It does not say how the time was spent or how it is spread. It ties together three numbers that are easy to measure and easy to get wrong.
Try it: three numbers, one equation
Section titled “Try it: three numbers, one equation”The lab below is the one from the previous lesson: four servers share one queue, each taking 20 ms on average, at 100 requests per second. It prints the equation for the setting you chose, under Requests in the system.
Requests arrive at a service with a few servers that share one queue. Raise the arrival rate toward what the servers can serve and watch the time a request spends in the system: it rises slowly at first and then sharply. Change the number of servers, the service time, and how much it varies.
Each dot stands for many requests. The numbers show the real rate.
No bottleneck: every component has headroom.
Response time at this load
- Utilisation
- 50%Busy
- Mean time in the system
- 21.7 ms1.1× the service time
- 99th percentile
- 95.3 ms95th percentile: 63 ms
- Requests in the system
- 2.20.2 of them waiting
Little's Law: 100 requests per second × 21.7 ms = 2.2 requests in the system on average.
Time in the system as utilisation rises
- Mean
- 95th percentile
- 99th percentile
A line that leaves the top of the chart keeps going up: the time grows without limit as utilisation approaches 100%.
Use the left and right arrow keys to move along the curve, and shift with an arrow to move ten points. The reading is announced.
| Utilisation | Mean | Times the service time | 95th percentile | 99th percentile |
|---|---|---|---|---|
| 50% · your load | 21.7 ms | 1.1× the service time | 63 ms | 95.3 ms |
| 70% | 27.1 ms | 1.4× the service time | 75 ms | 109.9 ms |
| 80% | 34.9 ms | 1.7× the service time | 94.8 ms | 137.9 ms |
| 90% | 59.4 ms | 3× the service time | 163.3 ms | 243.9 ms |
| 95% | 109.1 ms | 5.5× the service time | 310.4 ms | 471.3 ms |
| 99% | 509 ms | 25× the service time | 1.51 s | 2.31 s |
| Component | State | Utilisation | Offered (req/s) | Served (req/s) | Rejected (req/s) | p50 | p95 | p99 |
|---|---|---|---|---|---|---|---|---|
| Clients | Healthy | <1% | 100 | 100 | 0 | 0 ms | 0 ms | 0 ms |
| Service | Busy | 50% | 100 | 100 | 0 | 16 ms | 63 ms | 95 ms |
- Traffic
- 100 req/s
- Successful
- 100 req/s
- Error rate
- 0%
- Mean latency
- 22 ms
Illustrative values, not benchmarks of any real product.
Model notes
Assumptions
- Requests arrive at random, as a Poisson process, at a constant average rate.
- Each node is one queue, served first-come first-served by several identical slots (instances × concurrency).
- Service times are random with the stated mean; by default they are exponentially distributed.
- Each node is analysed separately, with the traffic it receives treated as Poisson.
- Requests arrive independently at random, at a steady average rate, and are served in the order they arrive from one shared queue.
Simplifications
- Above capacity there is no steady state. The model switches to a fluid approximation: the node serves at capacity, its queue grows until it reaches its limit, and further requests are rejected.
- Percentiles assume an exponential tail. A service-time variability other than exponential changes the mean wait but not the shape of the tail.
- A node frees its slot as soon as it has done its own work, before waiting on the services it calls. Real thread-per-request servers hold the slot, so a slow dependency exhausts them faster than this model shows.
- A request calls its dependencies one after another. Parallel fan-out is not modelled.
- When a caller times out and gives up, the callee still finishes the work, so abandoned requests keep consuming capacity.
- Retries add load. Their backoff and jitter decide when that load arrives, which only the per-request simulation shows.
- Retry feedback is solved from the healthy starting point, so it finds one stable outcome. Systems that stay stuck in overload after the cause is gone are not shown.
- A throughput limit (for example maximum writes per second) is modelled as slower service, not as a separate rate limiter.
- A caller’s timeout counts the mean time its dependencies take, not their full distribution.
- The curve is the steady state: it assumes the arrival rate has stayed the same for long enough to settle. A real system takes time to build a queue, and a short burst can fill one even below capacity.
- Service times are exponential in shape. The variability control changes the mean wait, by a factor of (1 + variability) ÷ 2, and not the shape of the tail.
Parameter values are illustrative. They are not benchmarks of any real product.
With the defaults the line reads 100 requests per second × 21.7 ms = 2.2 requests in the system, 0.2 of them waiting. Keep the arrival rate at 100 and change one setting at a time.
| Setting | Utilisation | Time in the system | Requests in the system |
|---|---|---|---|
| Defaults: 4 servers, 20 ms | 50% | 21.7 ms | 2.2, of which 0.2 are waiting |
| Servers sharing the queue at 3 | 66.7% | 28.9 ms | 2.9, of which 0.9 are waiting |
| Service time at 30 ms | 75% | 45.3 ms | 4.5, of which 1.5 are waiting |
| Service time at 38 ms | 95% | 207.4 ms | about 21, of which about 17 are waiting |
The arrival rate is the same in every row, so the number of requests in the system rises in step with the time each one spends there. In the last row, the system is holding about nine and a half times as many requests as in the first, and most of the extra are in the queue. Time in the system and the number in it are the same fact, seen from two sides.
Set Servers sharing the queue to 2 and the lab says that demand is at or above what the servers can serve. At 100 requests per second two servers of 20 ms can serve exactly 100, so there is no steady state: the queue keeps growing, and the averages keep rising the longer you look, so there is no single figure to read off.
Sizing a pool
Section titled “Sizing a pool”The most common use is to count how many requests are in flight, which is the number of connections, threads or workers needed. A service handles 500 requests per second, and each request holds one database connection for 80 ms. The number of connections in use at once is 500 × 0.080 = 40. A pool of 50 gives some headroom over the average.
The same arithmetic gives a ceiling. With a pool of N and a time of W per request, no more than N ÷ W requests per second can pass: 50 ÷ 0.080 = 625 per second. If the service needs 500, the pool is at 80% of that ceiling, and requests start to queue for a connection before the pool is full.
What happens if a dependency gets slower?
Section titled “What happens if a dependency gets slower?”The database slows down, and each query now takes 400 ms instead of 80. The service still receives 500 requests per second. By Little’s Law the connections it would need at once are 500 × 0.4 = 200. The pool has 50.
Only 50 requests can hold a connection at a time, so the pool can complete at most 50 ÷ 0.4 = 125 requests per second. The other 375 per second wait for a connection. Waiting adds to the time each request spends in the service, which raises the number of requests in it, which makes waiting longer for the next ones. If the service’s threads are all blocked waiting for a connection, they cannot serve anything else, including requests that never touch the database.
Nothing in the service’s own code changed. The number of requests inside it rose from 40 to at least 200 because the time each one stays rose fivefold. A rule of thumb follows: when latency rises, concurrency rises with it, and every pool that sits on the path needs to be sized for the slow case as well as the average one. The failure modules come back to this, with timeouts and limits that stop one slow dependency from filling every pool.
The lab below runs this on a small shop: an API in front of a cache and a database. The database serves its queries through a fixed number of connections, so by the same arithmetic it passes at most that number divided by the time a query takes. Before you press Slow the database, write down what you expect to happen to the requests that need the database, and to those that do not. Then try giving the database more connections, and run the failure again to compare. The lab is kinder than a real service in one way: its API does not keep a thread busy while it waits for the database, so the requests the cache can answer carry on, which the blocked threads described above would prevent.
Slow dependency (not dead)
The database is healthy, with its queries taking 8 ms and about a quarter of the requests needing it. You make it ten times slower: it still answers, only slowly, as it might under a heavy query, a lock or a failing disk. The API waits up to 300 ms for it and retries once. Watch what a dependency that is slow, but not dead, does to the system around it. Then compare with Kill the database.
The failure lab needs JavaScript. The healthy system is shown below.
1. Break it
The healthy system is shown first. When you press the button the failure strikes, and the run follows the 30 seconds after it.
What the failure does: The database still answers, but every query takes ten times as long.
Each dot stands for many requests. The numbers show the real rate.
No bottleneck: every component has headroom.
Cause and effect
Each step leads to the next. A step that is changing right now is marked.
- Traffic900 req/sNormal steady
- API utilisation75%Normal steady
- API queuenone waitingNormal steady
- Latency (p99)96 msNormal steady
- Timeouts and rejections0%Normal steady
- Errors0%Normal steady
| Component | State | Utilisation | Offered (req/s) | Served (req/s) | Rejected (req/s) | p50 | p95 | p99 |
|---|---|---|---|---|---|---|---|---|
| Clients | Healthy | <1% | 900 | 900 | 0 | 0 ms | 0 ms | 0 ms |
| Load balancer | Healthy | <1% | 900 | 900 | 0 | 0.03 ms | 0.15 ms | 0.23 ms |
| API | Busy | 75% | 900 | 900 | 0 | 14 ms | 60 ms | 93 ms |
| Cache | Healthy | 1% | 810 | 810 | 0 | 0.14 ms | 0.6 ms | 0.92 ms |
| Database | Healthy | 20% | 252 | 252 | 0 | 5.5 ms | 24 ms | 37 ms |
- Traffic
- 900 req/s
- Successful
- 900 req/s
- Error rate
- 0%
- Mean latency
- 24 ms
Sources
Illustrative values, not benchmarks of any real product.
Model notes
Assumptions
- Requests arrive at random, as a Poisson process, at a constant average rate.
- Each node is one queue, served first-come first-served by several identical slots (instances × concurrency).
- Service times are random with the stated mean; by default they are exponentially distributed.
- Each node is analysed separately, with the traffic it receives treated as Poisson.
- The system starts healthy at 900 requests a second. Three API instances can serve 1,200 a second and the database about 1,250 operations a second. Nine in ten requests read through the cache, which answers four in five of those reads; the rest, and every write, go to the database.
- A failure strikes at one instant and nothing repairs it during the run: no restart, no autoscaling, no operator. The load balancer notices a dead instance at once.
- The instances of a component are identical, and each request is independent of the others.
Simplifications
- Every query takes ten times as long, evenly. Real slowness often hits a few queries, because of a lock or a missing index, and spares the rest.
- While it waits for the database, a real API instance would hold a worker, so a slow dependency would exhaust the API tier too. Here it does not (see the engine’s notes), so the damage to the API is understated.
- A retry is a fresh, independent attempt with the same chance of failing as the last one. How long a real client library waits between attempts (backoff, jitter), and any retry budget or circuit breaker, are not simulated: attempts are counted, not scheduled.
- A client gives up when its first timeout runs out, so the latency shown stops at what a client would wait: the timeout of the first hop, times its attempts. After that the request counts as a failure.
- The cache's hit ratio is constant. Warming, stampedes and hot keys have their own labs.
- Nothing here models garbage collection, connection pools on the client, DNS, TLS handshakes, CPU throttling, noisy neighbours or cold caches. A real system fails in more ways, and in messier ones, than this model does.
- Above capacity there is no steady state. The model switches to a fluid approximation: the node serves at capacity, its queue grows until it reaches its limit, and further requests are rejected.
- Percentiles assume an exponential tail. A service-time variability other than exponential changes the mean wait but not the shape of the tail.
- A node frees its slot as soon as it has done its own work, before waiting on the services it calls. Real thread-per-request servers hold the slot, so a slow dependency exhausts them faster than this model shows.
- A request calls its dependencies one after another. Parallel fan-out is not modelled.
- When a caller times out and gives up, the callee still finishes the work, so abandoned requests keep consuming capacity.
- Retries add load. Their backoff and jitter decide when that load arrives, which only the per-request simulation shows.
- A caller’s timeout counts the mean time its dependencies take, not their full distribution.
- Latency percentiles for a whole request are estimated, over every request, including those that are rejected and fail quickly. The mean is exact, and the percentiles come from a gamma distribution that has that mean and the variance of the time spent in each component.
Parameter values are illustrative. They are not benchmarks of any real product.
Using it backwards
Section titled “Using it backwards”Little’s Law also answers questions about people. An online shop has 30,000 visitors on the site at its busiest, and each stays 10 minutes on average. The rate at which visitors arrive is L ÷ W = 30,000 ÷ 600 seconds = 50 per second. This is the kind of estimate the capacity-estimation module builds on: start from the number of people present and the time each stays, and work out the rate.
- Little’s Law: L = λ × W. The average number of requests in a system equals their arrival rate times the average time each stays.
- It holds whatever the distributions and the service order, for a whole system or any part of it, when the three averages are taken over the same period.
- In the lab at 100 requests per second, 21.7 ms in the system means 2.2 requests inside, and 207.4 ms means about 21.
- It sizes pools: 500 requests per second at 80 ms is 40 connections busy at once, and a pool of N with time W passes at most N ÷ W requests per second.
- When a dependency slows down, concurrency rises with latency. At 400 ms the same service wants 200 connections, and a pool of 50 can pass only 125 requests per second.
- Used backwards, it turns people present and time on site into an arrival rate: 30,000 visitors for 10 minutes each is 50 arrivals per second.
Next: utilisation and queueing, and why the last 10% of capacity costs so much.
Your progress
Built by GhaziAlibi.
© ShardCraft. All rights reserved.