Fundamentals
Little's law
A one-line formula that links how many items are in a system, how fast they arrive, and how long each one stays. It sizes queues, worker pools and servers.
Suppose a restaurant has a steady stream of customers, and each one stays about 30 minutes. How many tables do you need? You don't need to know anything fancy. You need to know how many people arrive per minute and how long they stay. Little's law says exactly that.
The big idea
Little's law says, for any stable system:
L = λ × W
L = how many items are inside the system at once
λ = how fast items arrive (per second, per minute, ...)
W = how long each item stays insideThe units must match. If λ is per minute, W must be in minutes.
Concept
A system here is anything with a queue of work in it: a restaurant, a web server, a queue with workers. "Stable" means work doesn't pile up forever. Arrivals are no faster than the system can serve them.
Walking through the restaurant
Customers arrive at 2 per minute. Each stays 30 minutes.
λ = 2 customers/min
W = 30 min
L = 2 × 30 = 60 customers seated at onceYou need room for 60 people at any moment, even though only 2 walk in each minute. The formula doesn't care how the arrivals are spread out. It only uses averages.
Now double the stay to 60 minutes because the kitchen got slower. L becomes 120. Nothing about the arrivals changed, but you need twice the seats.
Worked example: sizing a worker pool
A queue receives 2,000 messages per second. Each message takes 0.25 seconds to process.
λ = 2,000 messages/s
W = 0.25 s
L = 2,000 × 0.25 = 500 messages being processed at any momentEach worker process runs 8 messages at once, because its time is mostly spent waiting on a database.
workers at 100% busy = 500 / 8 = 62.5 -> 63 workers
workers at 70% busy = 63 / 0.7 = 90 workers (headroom for spikes)Keeping workers at about 70% busy is a common rule of thumb. It leaves room for bursts without queueing time exploding.
Common mistakes
- Mixing units. λ per second with W in minutes gives an answer 60 times too big or too small.
- Forgetting the system is unstable. If arrivals are faster than capacity, L grows without limit and the formula gives no useful steady state.
- Ignoring that W grows. A slow database doesn't just slow each request. It increases W, which increases L, which needs more workers. This is how a small slowdown becomes an outage.
Warning
When a dependency doubles its latency, you need twice the in-flight capacity to keep up with the same traffic. Autoscaling workers can't fix a bottleneck that is a shared database.
Key takeaways
L = λ × W: items in the system = arrival rate × time each stays.- Use it to size worker pools, connection pools and server concurrency.
- Keep the units consistent, and remember it only works for stable systems.
- Latency is not just a user problem. Higher W means more work in flight.
Further learning
Next, see how this plays out in backpressure and autoscaling for queues, and in message queues for the bigger picture.
Related
Backpressure and autoscaling
A queue only stores work, it doesn't create capacity. Learn how to tell when the backlog is growing, how to scale workers on the right signal, and what to do when you can't add more.
Message queues
A durable buffer between the code that creates work and the code that does it. Start here for the map of queue concepts.
Scaling fundamentals
Vertical versus horizontal scaling, stateless services, the usual order in which a growing system adds parts, and how to find the real bottleneck. Start here for the scaling map.