Quick revision
The short answer
A rate limit caps how many requests arrive per second, not how many are in progress. By Little's law, requests in flight equal arrival rate times latency: 2,000 per second at 50 ms is 100 in flight, but at 2 seconds it is 4,000, far beyond the threads and connections available, so the service collapsed while staying under its rate limit. A concurrency limit caps requests in flight and rejects the rest quickly, and an adaptive limiter such as AIMD or a gradient algorithm moves that cap based on measured latency. Use rate limits for fairness between clients and concurrency limits for self-protection.
What to remember
In this answer, we used Little's law to see that 2,000 requests per second at 2 seconds of latency means 4,000 requests in flight, twenty times the threads available, even though traffic never exceeded the rate limit. We saw that a concurrency limit caps work in progress and keeps the service alive by rejecting fast, that adaptive limiters such as AIMD and gradient algorithms move that limit with measured latency, and that rate limits for fairness and concurrency limits for self-protection belong together.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
A rate limit caps how many requests arrive per second, not how many are in progress. By Little's law, requests in flight equal arrival rate times latency: 2,000 per second at 50 ms is 100 in flight, but at 2 seconds it is 4,000, far beyond the threads and connections available, so the service collapsed while staying under its rate limit. A concurrency limit caps requests in flight and rejects the rest quickly, and an adaptive limiter such as AIMD or a gradient algorithm moves that cap based on measured latency. Use rate limits for fairness between clients and concurrency limits for self-protection.
Why this question is asked
Rate limits feel like protection, so it is a surprise when a service collapses while traffic stays well under its limit. The explanation is one of the most useful formulas in system design, and interviewers ask this question to see whether we know it and can apply it to thread pools and connection pools. In this answer, we will recap Little's law, apply it to the incident, see why a concurrency limit protects where a rate limit cannot, look at how adaptive limiters find the right limit on their own, and finish with how to reject requests well and how rate and concurrency limits work together.
1A Quick Recap of Little's Law
Little's law says that in a stable system, the average number of items inside equals the arrival rate times the average time each item spends inside: L = lambda x W. For a service, L is the number of requests in flight, lambda is requests per second and W is latency. It holds for any system in a steady state, regardless of how requests are distributed, which makes it very handy for quick estimates.
Every request in flight holds resources: a thread in a servlet container such as Tomcat, a database connection from a pool such as HikariCP, memory for its buffers. So 'requests in flight' is really 'resources in use', and that is what a service runs out of.
2Applying It to the Incident
At normal latency, the search service has 2,000 requests per second x 0.05 seconds = 100 requests in flight. With a thread pool of, say, 200 threads and 50 database connections that are each held for part of the request, there is plenty of headroom.
Then the database slows down and latency rises to 2 seconds. Traffic has not changed: still 2,000 per second, comfortably under the rate limit, so the limiter lets everything through. But now L = 2,000 x 2 = 4,000 requests in flight. The 200 threads are all busy waiting for the database, the remaining requests queue in the server's accept queue, their latency grows further because they wait for a thread first, and timeouts and client retries add even more arrivals. Health checks also time out, so the load balancer may start removing instances, which pushes the same traffic onto fewer of them. The service collapses at a rate it handled easily an hour before.
| Latency | Arrival rate | In flight (L = rate x latency) | With 200 threads |
|---|---|---|---|
| 50 ms | 2,000 per s | 100 | fine, half the pool idle |
| 200 ms | 2,000 per s | 400 | pool full, requests queue |
| 2 s | 2,000 per s | 4,000 | collapse: 20 times the pool |
3Why a Concurrency Limit Protects Where a Rate Limit Cannot
A rate limit controls arrivals per second. A concurrency limit controls requests in flight: when a request arrives and the number in flight is at the limit, it is rejected immediately (or put in a very short queue) instead of being accepted and left to wait. Because resources scale with requests in flight, not with arrivals, a concurrency limit bounds resource use whatever the latency does.
With a concurrency limit of 150, during the slowdown the service keeps 150 requests in progress and rejects the rest quickly. The 150 it accepts get a thread and a connection and finish in about 2 seconds; the service stays alive, its health checks pass, and as soon as the database recovers, throughput returns without a restart. Rejected clients get a fast error instead of a 30-second timeout, which is better for them too. In Java this can be as simple as a semaphore around the handler, or a bulkhead from Resilience4j.
4Adaptive Limiters: Finding the Right Limit Automatically
A fixed concurrency limit is hard to pick: too low wastes capacity when everything is healthy, too high lets the service overload. Adaptive limiters adjust the limit from what they measure, borrowing ideas from TCP congestion control.
AIMD, additive increase and multiplicative decrease, raises the limit by one for each period in which latency stays healthy, and cuts it by a factor, for example to 90 percent or half, as soon as latency rises above a threshold or requests fail. It probes upward slowly and backs off quickly. Gradient algorithms compare the current latency with a baseline, the minimum latency seen recently: if latency is close to the baseline, there is no queueing and the limit can grow; if latency is twice the baseline, requests are queueing somewhere and the limit shrinks proportionally. Netflix's concurrency-limits library implements several of these for Java, and Envoy has an adaptive concurrency filter that does it at the proxy, using a gradient against a periodically measured minimum round-trip time.
- Measure latency over the last windowfor example p90 every second
- Latency healthy and no errors?YesRaise limit by 1NoCut limit to 90 percent
- Apply the limit to new requestsrequests above it get 503 at once
- Repeat each windowthe limit tracks what the service can really handle
4 steps in order. Play them, or step through them one at a time.
5Rejecting Well, and Using Both Kinds of Limit
When the limit is reached, the service rejects fast with 503 Service Unavailable (it is protecting itself) or 429 Too Many Requests (a particular client is over its share), with Retry-After, so well-behaved clients back off instead of retrying immediately. Clients should use exponential backoff with jitter and a retry budget, because retries during an overload add arrivals exactly when the service can least afford them.
Rate limits and concurrency limits answer different questions, so large systems need both. Rate limits per client give fairness: one customer cannot use the whole service. Concurrency limits per instance give self-protection: the service never accepts more work than it can complete, whatever the cause of the slowdown.
6Follow-up questions
Where should the concurrency limit sit: at the gateway or in the service?
Both can help. A limit in each service instance protects its own threads and connections and reacts to its own latency. A limit at the gateway or proxy, such as Envoy's adaptive concurrency filter, rejects before the request even reaches the instance, which saves more resources. Many teams start with the service-level limit and a per-dependency bulkhead around the database calls, because that is where the resource actually runs out.
Why not just add a timeout?
Timeouts limit how long one request can hold resources, which helps, but with 2-second database latency and a 3-second timeout every request still holds a thread for 2 seconds, so the in-flight count is the same. Timeouts and concurrency limits work together; neither replaces the other.
7Conclusion
In this answer, we used Little's law to see that 2,000 requests per second at 2 seconds of latency means 4,000 requests in flight, twenty times the threads available, even though traffic never exceeded the rate limit. We saw that a concurrency limit caps work in progress and keeps the service alive by rejecting fast, that adaptive limiters such as AIMD and gradient algorithms move that limit with measured latency, and that rate limits for fairness and concurrency limits for self-protection belong together.
Open with
The rate limit capped arrivals, but what kills a service is work in progress. Little's law says requests in flight equal arrival rate times latency. At 2,000 per second and 50 milliseconds, that is 100 requests in flight, which fits easily in the thread pool and connection pool.
Then, if they want more
When the database slowed down to 2 seconds, the same 2,000 per second meant 4,000 requests in flight. Traffic was still under the rate limit, so nothing stopped it, the threads all blocked on the database, requests queued, timeouts and retries added more load, and the service collapsed. A concurrency limit protects against exactly this.
It caps the number of requests in flight and rejects the extra ones immediately, so resource use stays bounded whatever the latency does, and the service keeps working on the requests it accepted. Choosing a fixed number is hard, so I would use an adaptive limiter.
AIMD adds one to the limit while latency is healthy and cuts it by a factor when latency rises; gradient algorithms compare current latency with a baseline minimum. Netflix's concurrency-limits library and Envoy's adaptive concurrency filter do this. When the limit is hit, I return 503 or 429 with Retry-After so clients back off.
And I would keep both: rate limits for fairness between clients, concurrency limits for self-protection.
About this answer
- Last updated
- 13 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the official documentation for the version you use. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "Why did the rate limit not protect the service, and how do concurrency limits and...": https://scrivio-interview-library.netlify.app/architecture/api-design-at-scale/d619c75e7b/