LOAD SHEDDING
Drop some requests on purpose so you can serve the rest
Capacity 100 req/s, clients time out after 2 s, load 120 req/s, every request admitted. After 30 seconds, how many requests per second complete in time?
A server handles 100 req/s and clients give up after 2 s. Send it 120 req/s and admit everything: the queue grows by 20 requests every second. After ten seconds the oldest request has waited 2 s, and from then on every request the server picks up belongs to a client that has already hung up. The server runs flat out and its goodput, work finished while someone still wants it, is zero.
Load shedding rejects the excess before it costs anything. Shed low priority first when the queue gets deep, and shed everything once the queue holds more work than any client will wait for. 80% of the traffic stays fast instead of 100% being useless.
app.use((req, res, next) => next()); // admit everything
// At 120% load the queue grows 20 req/s. After ~10 s every request
// waits > 2 s, every client has hung up, and the server is 100% busy doing nothing useful.app.use((req, res, next) => {
const depth = server.pendingRequests();
if (depth >= 100) return res.status(503).end(); // 1 s deep: nobody admitted now would be served in time
if (depth > 50 && req.get('x-priority') === 'low') return res.status(503).end();
next();
});
// Rejecting costs microseconds. Serving a request whose client has left costs 10 ms and helps no one. Watch the invariant strip in SERVE EVERYTHING: goodput holds at 100 req/s while the queue grows, then, a little after the queue holds more than 2 s of work, it falls to 0 within a couple of seconds and both checks turn red. In FIX: SHED LOW PRIORITY the same 120 req/s arrive, the queue never passes 52, and goodput stays at 100 with no high-priority request rejected. SHED WITHOUT PRIORITY also keeps goodput, but 374 of its rejections are high priority.
Lower LOAD step by step. Find the lowest load at which serving everything ends the run with less goodput than shedding would at the same load.
GOAL: serve-everything goodput < shedding goodput at this LOAD, and not at LOAD − 10
Rewrite admit so the server keeps its goodput through a burst at 150% of capacity: reject low-priority requests first when the queue is deep, reject everything once the queue holds a second of work, and reject nothing when there is room. Clients give up after 2 s.
Admission control in Envoy and gRPC, max_requests limits, concurrency limiters like Netflix's adaptive limit, HTTP 503 and 429 with Retry-After, priority headers and request criticality in the Google SRE book. The symptom without it: servers at 100% CPU, dashboards green on throughput, users seeing nothing but timeouts.
“Traffic is 20% above capacity. What happens, and what do you do?” Explain the queue growing until every request is served too late, then say you shed by priority on queue depth, serve the rest fast, and that the dropped 20% should get a fast rejection they can retry later with backoff. Mention that autoscaling is too slow to be the only answer.
USED IN
Chapters that build on this lesson.
- Performance and load testingQA and Quality Engineering
- Testing in production and observabilityQA and Quality Engineering
- Capacity and costSRE, Platform and DevOps
- Chaos and resilience testingSRE, Platform and DevOps
- Production readiness reviewsSRE, Platform and DevOps
- Leading a sev-1 as the technical leadStaff and Principal Engineer