How to Shed Load with Admission Control
Reject excess work at the door so a service stays responsive for the requests it accepts instead of timing out for all of them.
On this page
Introduction
When a service is overloaded, accepting every request makes it serve none of them well: queues grow, latency climbs, and eventually every request times out, including the ones that would have been fast. Admission control rejects excess work before it consumes resources, so the requests that are accepted get served promptly. The principle is that it is better to fail a few requests quickly than to fail all of them slowly. This article covers what admission control protects, how to bound concurrency, how to prioritise, and how to communicate a rejection so a client can retry sensibly.
When to Reject Work
A service has finite capacity, and beyond it, additional requests do not increase throughput; they increase latency and eventually errors. The moment of overload is when admitting more work reduces the quality of the work already admitted. Admission control rejects new work at that point so the accepted work completes within the latency target.
The alternative, accepting everything, leads to a queue that grows without bound and a latency that grows with it, until timeouts fire for every request. The service appears to fail completely rather than degrading gracefully. Rejecting a fraction keeps the rest healthy, which is the more useful failure.
A Concurrency Limit
The simplest admission control is to bound the number of requests in flight. When the limit is reached, new requests are rejected immediately or wait a bounded time and are rejected if the limit is still reached. This keeps the work in progress and the memory it consumes bounded, and it keeps latency predictable because the queue cannot grow.
const MAX_INFLIGHT = 200;
const MAX_WAIT_MS = 50;
let inflight = 0;
async function handle(req, res) {
if (inflight >= MAX_INFLIGHT) {
// Wait briefly for capacity, then reject rather than queue without bound.
const admitted = await Promise.race([
waitForCapacity(),
new Promise((r) => setTimeout(() => r(false), MAX_WAIT_MS)),
]);
if (!admitted) {
res.writeHead(503, { 'Retry-After': '1' });
res.end('server busy');
return;
}
}
inflight++;
try {
await processRequest(req, res);
} finally {
inflight--;
}
}
Priority and Fairness
Not all requests are equal. A health check should always be admitted; a background export should be the first to shed. Assign priorities and reserve capacity for the critical ones, so under overload the service sheds the low-priority work and keeps the user-facing path alive. Without priorities, shedding is arbitrary and may reject the very requests that matter.
Per-tenant or per-client limits prevent one caller from consuming all capacity, which is a fairness issue as much as a reliability one. A single client sending a burst should be limited to its share, so other clients keep working. This is the intersection of admission control and rate limiting: rate limiting bounds a client’s request rate, admission control bounds the service’s concurrent work.
// Reserve capacity for critical requests; shed low-priority ones first.
const PRIORITY = { critical: 3, normal: 2, background: 1 };
const MAX_INFLIGHT = 200;
const RESERVED_FOR_CRITICAL = 40; // never used by background work
const inflightByPriority = { critical: 0, normal: 0, background: 0 };
function admit(priority) {
const total = Object.values(inflightByPriority).reduce((a, b) => a + b, 0);
if (priority === 'critical') return inflightByPriority.critical < MAX_INFLIGHT;
if (priority === 'normal') return total < MAX_INFLIGHT - RESERVED_FOR_CRITICAL;
// background is admitted only into the unreserved capacity
return total < MAX_INFLIGHT - RESERVED_FOR_CRITICAL;
}
Communicating Rejection
A rejection must tell the client what happened and what to do: a status that indicates temporary overload, a retry-after header, and a body that is clear. A 503 with a retry hint lets a well-behaved client back off and retry, and it distinguishes the overload from a permanent failure so the client does not retry forever.
Never reject with a generic error that the client treats as permanent, or the client will surface a failure to the user when a retry would have succeeded. Conversely, never accept work you know you cannot complete within a reasonable time; that just moves the timeout to the client. The rejection is a contract: attempt again later.
Combining with Autoscaling
Admission control and autoscaling are complementary. Autoscaling adds capacity in response to load, but it is slow, so it cannot protect the service during the spike before it reacts. Admission control protects during that window by shedding, and autoscaling reduces the frequency of shedding by adding capacity for a sustained increase.
Shedding is also a signal to scale: sustained rejections mean the service is under-provisioned, and the rejection rate is a metric to alert on and to use as a scaling input. Without that link, a service that sheds constantly is a service that needs more capacity, not one that is working as designed.
Measuring Shedding
Count the rejections and watch the rate. Some shedding during a spike is healthy and expected; sustained shedding means the limits are too tight or the capacity too low. Break the count down by priority and by client so you can see whether the service is shedding the right work or punishing a client unfairly.
Report latency alongside the shed rate, because the goal is to keep the accepted requests fast. If latency stays within target while the shed rate rises to a ceiling, admission control is doing its job. If latency rises even with shedding, the limit is too high or the accepted requests are too expensive.
Conclusion
Admission control keeps a service responsive under overload by rejecting excess work before it consumes resources, so the accepted requests are served promptly. Bound the in-flight requests, prioritise so critical work is admitted first and low-priority work is shed, limit per-client consumption for fairness, and reject with a retry hint so clients back off. Combine it with autoscaling to reduce how often it fires, and measure both the shed rate and the latency of accepted requests. Then overload degrades the quality of a few requests instead of failing all of them.
Sources: Google SRE Book: Handling Overload, Google SRE Book: Load Shedding, AWS: back pressure and load shedding.
FAQ
- How is admission control different from rate limiting?
- Rate limiting bounds how many requests a client may send over time. Admission control bounds how much work the service admits concurrently, regardless of the client. They complement each other: rate limiting controls the arrival rate, admission control protects against overload.
- What status should a rejected request return?
- A status that marks the rejection as temporary, such as 503 with a Retry-After header, so a well-behaved client backs off and retries. A generic permanent error makes the client give up on a request that a retry would have served.
Report a problem with this articleOpens a pre-filled issue on GitHub.