Admit only what you can finish
Accepting every request means all of them slow down together once the queue grows past what can be served within the deadline.
Say it like this
Queueing more work than we can finish inside the deadline only makes every request late, so each service caps its in-flight requests at a limit learned from latency, rejects beyond it immediately, and drops any request whose deadline has already passed.
Basic solution
Bound in-flight work per service (concurrency limit) and reject new work when the bound is hit; adapt the limit from observed latency, and reject requests whose deadline has already passed.
Adaptive limit and deadline check at the worker
The worker pulls only up to its current limit from the queue. Each message is checked against its deadline on arrival; expired ones are dropped, admitted ones run at full speed, and latency feedback tunes the limit.
How it works
- Each service keeps two numbers: how many requests it is working on right now (in-flight) and a concurrency limit. The limit starts at a value measured in a load test and then adapts: while latency stays close to the best latency seen, the limit creeps up; when latency rises, the limit drops. This is the same idea TCP uses to find how much it can send.
- When a request arrives, the service compares in-flight with the limit. Below the limit, the request is admitted and in-flight increases by one. At or above it, the request is rejected at once with a 503 or 429, before any work is done.
- Every request carries a deadline, an absolute time by which the caller needs an answer, set at the edge and passed along on each hop. On arrival the service checks it: if the deadline has passed, or less time remains than the service typically needs, the request is rejected, because finishing it would help nobody.
- While a request runs, the service measures how long it waited in any internal queue before a thread picked it up. If that wait exceeds a target, the limit shrinks.
- Inside the global limit, each tenant or traffic class has its own smaller quota, so one caller cannot occupy every admitted slot.
- The service exports the current limit, the number of rejections, and the reason for each (over the limit, or deadline expired).
The idea in one line
- Keep the service at the top of its throughput curve, where adding work would add only latency.
Worked example
Notification router workers
- The router applies preferences and renders templates at about 4 ms of CPU per message, around 40 ms of wall time once the I/O is included; capacity is about 250 messages/s per worker.
- A marketing campaign enqueues 20M messages in 10 minutes, 33K/s, against 40 workers that can do 10K/s.
- Without admission control: each worker pulls as many messages as it can hold; the in-process queue grows, per-message latency climbs from 40 ms to seconds as threads contend, and throughput actually falls to 7K/s because of context switching and GC. Transactional OTPs in the same workers wait minutes.
- With a concurrency limit per worker learned from latency: the limit settles around 10 (250/s × 40 ms with headroom). Each worker admits 10 messages at a time and leaves the rest in the broker queue; latency per admitted message stays near 40 ms, throughput holds at 10K/s. The marketing queue drains in 33 minutes instead of growing without bound.
- Deadlines: OTPs carry a 60 s deadline from the API. A message that waited longer than that in the queue is dropped on arrival with a "deadline expired" metric, so a worker never renders and sends an OTP the user already gave up on.
- Per-class quota: transactional traffic is guaranteed 4 of the 10 slots on each worker, so OTP latency stays under 100 ms during the campaign.
Variants and when each wins
Static concurrency limit
- A fixed cap on in-flight requests per instance, taken from a load test. It wins for predictability, but must be re-measured after any change in hardware or code.
Adaptive limit (gradient or AIMD)
- The limit follows measured latency, growing while latency is flat and shrinking when it rises. It wins because it tracks real capacity as dependencies slow down; the Netflix concurrency-limits library is the usual reference.
Queue-timeout (CoDel)
- Every request enters a queue, and any request that has waited past a target is dropped. It wins for services with a single queue because it is simple and effective, though it does not bound memory on its own.
Deadline propagation
- Each hop subtracts the time already spent and refuses work it cannot finish in what remains. It wins across a whole call chain, because wasted work is prevented at every service rather than at one.
Recommendation: adaptive concurrency plus deadline propagation at every service, with per-class quotas inside the limit where traffic classes share a worker.
Failure modes
Limit too low after a dependency slowdown
- A 10-second database hiccup drops the limit to 1, and it takes minutes to climb back. It happens because the limit is designed to shrink fast and grow slowly. Put a floor under the limit, and let it grow faster once latency returns to normal.
Deadline clocks disagree
- Requests are rejected as expired the moment they arrive. It happens because the clock on the edge and the clock on the service differ by more than the deadline margin. Propagate the remaining time in milliseconds instead of an absolute timestamp, and subtract the measured latency of each hop.
Rejecting is expensive
- Under overload the service is still slow even though it rejects most requests. It happens because each rejection logs a stack trace and runs the full middleware chain. Reject in the first middleware and record nothing beyond a counter.
Limit shared across unequal work
- A few heavy requests occupy every slot while cheap ones are rejected. It happens because one limit counts every request as equal cost. Weight requests by their expected cost, or give each request type its own pool, which is a bulkhead.
Retries ignore the rejection
- Rejected callers retry instantly and the service spends its capacity saying no. It happens because the callers treat 503 as a transient error to retry at once. Return Retry-After with jitter on rejections, and make callers treat 503 as a signal to back off.
Nobody watches the rejection counter
- Five percent of requests have been rejected for a week without anyone noticing. It happens because the counter exists but has no alert. Alert on the rejection rate and on the limit falling below a threshold.
Interviewer follow-ups
Answer out loud before you open each one.
How is this different from a rate limiter?
A rate limiter enforces a per-client contract in requests per second, independent of how healthy the server is. Admission control bounds the server’s own in-flight work based on how fast it is finishing, independent of who is calling. One protects fairness, the other protects latency.
How does the adaptive limit decide to grow or shrink?
It compares recent latency with the best latency it has seen. If recent latency is close to the minimum the service has spare capacity, so the limit grows by one. If latency has risen by more than a tolerance the service is queueing internally, so the limit shrinks, often multiplicatively. The result hovers at the knee of the latency curve.
Why propagate deadlines instead of just using timeouts?
A timeout tells the caller when to give up; it does not tell the callee, so the callee keeps working on a request nobody is waiting for. A propagated deadline lets every hop stop early, and a service three hops deep can refuse work that has 5 ms left when it needs 20. That stops overload from turning into pure waste.
What should you do with the work you reject?
For synchronous user requests, return a fast 503 with Retry-After and let the client decide. For queued work, leave it in the broker; admission control just means pulling less at a time, so the backlog is visible in queue depth and drains when capacity allows. Never silently drop queued work that has not expired.
Connections
- In study paths
- Staying up under load
- Pairs with
- Drop load before you fall over · Never wait forever · Slow the producer when the consumer is behind · Isolate failures · Keep urgent work ahead of bulk work
- Pulls against
- Retry transient failures carefully
- Used in
- Distributed Rate Limiter · Notification System
The same parts on other clouds
The diagrams above name AWS services as one concrete example. Every part has a close equivalent elsewhere. In an interview, name the role first, such as “a managed Redis cache”, then the product you would pick.
| AWS | Used here as | Google Cloud | Microsoft Azure | Open source and others |
|---|---|---|---|---|
| Amazon SQS | Marketing queue, Transactional queue | Pub/Sub, Cloud Tasks | Service Bus queues, Queue Storage | RabbitMQ, ActiveMQ |
| Amazon EC2 Auto Scaling | Render and send | Compute Engine managed instance groups | Virtual Machine Scale Sets | Kubernetes Deployment with a HorizontalPodAutoscaler, Nomad |