Keeping Latency SLOs Alive During Traffic Spikes
System DesignModel answerLast updated
Design a layered overload protection system that sustains goodput and p99 latency targets when request volume suddenly surges beyond provisioned capacity.
The Scenario
Your team runs a high-traffic API — think a content feed or recommendation engine — serving roughly 500,000 requests per second at steady state. Twice a year, a live event or a mass push notification drives traffic to 3× that in under 10 seconds. Autoscaling takes 2–5 minutes to kick in. During that gap, without protection, latency collapses and the service becomes effectively unavailable for everyone.
Your job is to design a system that stays useful under that spike: not zero errors, but a graceful degradation where high-value requests still succeed within SLO.
What You're Expected to Cover
Requirements and scale State your assumptions. What are the SLOs (latency, availability)? What are the traffic classes? What is out of scope (e.g., DDoS scrubbing)?
Request contract and metadata How do priority, deadlines, and tenant identity flow through the stack? How do clients and downstream systems know a request was shed versus failed?
Architecture overview Sketch the layers — edge/load balancer, app-level admission, priority queues, worker pool, dependency calls — and explain the principle behind shedding decisions at each layer.
Rate limiting mechanics Explain token buckets: the parameters, what they protect against, and where they fall short.
Adaptive admission control Why is a static RPS cap insufficient? How does an adaptive concurrency limit work, and how does it differ from a token bucket?
Priority queues and deadline propagation How do you bound queues from the latency budget? What is deadline-aware dequeuing? When does LIFO beat FIFO under sustained overload?
Load shedding strategies Compare at least four strategies (drop-new, drop-tail, random/probabilistic, deadline-aware): mechanics, trade-offs, and where in the stack each belongs.
Circuit breakers and backpressure How do circuit breakers prevent a slow dependency from cascading? What backpressure signals go to upstream callers and queues?
Metrics and validation What do you instrument to know the system is working? How do you distinguish a spike that was handled well from one that was not?
Hints
Hint 1
Start by deriving a concrete queue depth limit from the latency budget using Little's Law — this single number drives most of the design decisions that follow.
Hint 2
Token buckets catch expected abuse from known clients, but they cannot detect that your own server has slowed down due to GC or a noisy neighbor. A separate mechanism owns that case.
Hint 3
When comparing shedding strategies, think about what information is available at each layer: the load balancer knows IP, tenant, and route; the app knows priority, cost, and deadline. Match strategy to information.
Model answer
Hard Try it yourself first — then compare your approach, complexity and edge cases.
What the question is really testing
Autoscaling is not fast enough. The design question is what keeps the service useful during the minutes before new capacity arrives. A strong answer shows three things: overload is handled in layers; each layer sheds using the information available to it; and every mechanism is validated with metrics.
1. Assumptions and scale
State these explicitly rather than leaving them implicit:
- Service: recommendation/feed API. Steady load: 500k RPS. Spike target: 1.5M RPS within 10 seconds.
- SLO: p99 latency under 200 ms for admitted requests. 99.9% availability for P0 traffic.
- Per-instance capacity: ~1,000 RPS at ~50 ms mean service time.
- Traffic classes: P0 (login, payments, first feed page), P1 (interactive scrolling, comments), P2 (prefetch, analytics, batch).
- Out of scope: DDoS scrubbing, which belongs at the CDN/edge before this system.
Key derived constraint — queue depth budget:
By Little's Law: in-flight = throughput × latency. At 1,000 RPS and 50 ms mean service time, an instance holds ~50 requests in flight at saturation. The 200 ms p99 budget minus ~80 ms of p99 service time leaves about 100 ms for queueing. At 1,000 RPS that is roughly 100 queued requests per instance. Any request beyond that will miss SLO regardless, so rejecting it immediately costs nothing in goodput.
2. Request contract
Every request carries three pieces of metadata, propagated through gRPC metadata or HTTP headers:
X-Priority(P0/P1/P2): assigned by the gateway from route and client type, never trusted from the client.X-Deadline: an absolute timestamp. Each hop subtracts elapsed time and passes the remainder downstream. Never let a downstream timeout exceed the upstream deadline.X-Tenant/ client ID: used for per-tenant fairness buckets.
Under overload, the server responds with 429 Too Many Requests (or gRPC RESOURCE_EXHAUSTED) plus Retry-After, and a distinct header (X-Shed: true) so dashboards and clients can separate shed requests from errors.
3. Architecture
Client (retry budget, backoff+jitter, adaptive throttling)
→ Edge / L7 LB (per-tenant token buckets, connection caps, random early drop)
→ App instance
admission controller (adaptive concurrency limit, CPU guard)
→ priority queues P0 / P1 / P2 (bounded, deadline-aware, LIFO under sustained load)
→ worker pool
→ per-dependency bulkheads + circuit breakers + propagated timeouts
→ caches, databases, downstream services
The governing principle: shed as early as possible, but only where you have enough context to shed correctly. The LB is cheap — reject before the app parses the body — but it only knows IP and route. The app knows deadline and priority. Match the mechanism to the available signal.
4. Token-bucket rate limiting
A bucket refills at rate r tokens/second and holds at most b tokens (the burst allowance). Each request consumes one token (or a cost-weighted amount for expensive endpoints). Use per-tenant buckets so one abusive client cannot crowd out others, plus a global bucket per route.
Where token buckets fall short: they enforce a rate but they do not detect that the server itself has slowed down — due to GC, a slow database, or a noisy neighbor. A bucket set to 1,000 RPS still admits 1,000 requests/second while they pile up in the thread pool. Adaptive admission control owns that case.
5. Adaptive concurrency limits
Instead of a static RPS cap, limit in-flight requests per instance and adjust the limit dynamically (AIMD or gradient algorithm, as in Netflix's concurrency-limits library):
- Latency stays near the no-load baseline → increase the limit by 1.
- Latency exceeds ~2× baseline → multiply the limit by ~0.9.
This discovers real capacity automatically, reacts in milliseconds, and self-corrects as request cost changes. Add a CPU guard as a backstop: start shedding P2 above 80% CPU, P1 above 90%.
6. Priority queues and deadlines
Maintain a separate bounded queue per priority class, sized from the budget derived in step 1. Dequeue with strict priority but reserve a small weighted share (~5%) for lower classes to prevent complete starvation.
At dequeue, check the deadline: if remaining_deadline < expected_service_time, drop the request without doing the work. Re-check before each expensive downstream call (fan-out, DB query). This is deadline-aware shedding: never spend CPU on a request that will arrive late anyway.
LIFO under sustained overload: the newest requests still have deadline headroom; the oldest have likely been abandoned by the client. Switching from FIFO to LIFO during a sustained overload window increases goodput without changing throughput. CoDel offers a principled alternative: if the minimum queue wait over a 100 ms interval exceeds 5 ms, you have a standing queue — reduce the queue timeout accordingly.
7. Load shedding strategies compared
| Strategy | How it works | Best for | Weakness |
|---|---|---|---|
| Drop-new (admit-gate) | Reject on arrival when the concurrency limit or token bucket is exhausted | First line everywhere; cheapest | Not priority-aware unless combined with traffic classes |
| Drop-tail (bounded FIFO) | Queue fills; overflow drops | Simple proxies with very short queues | Latency inflates before drops occur; standing queues |
| Random / probabilistic (RED) | Drop probability rises with load | LB/edge where business context is absent; avoids synchronised retries | Ignores value and deadline; may shed P0 |
| Deadline-aware | Drop requests that cannot finish before their deadline | Inside the app, at dequeue and before fan-out | Requires deadline propagation and service-time estimates |
LB vs. application: use the LB for coarse token buckets, connection caps, and random early drop as the cluster approaches capacity. Use the application for priority-aware and deadline-aware shedding and adaptive concurrency, where the full request context is available. Rejection must cost far less than serving — reject before deserializing large bodies.
8. Circuit breakers, bulkheads, backpressure
Circuit breakers sit in front of each downstream dependency. States: closed (normal), open (failing fast after threshold), half-open (probing). When a dependency degrades, the circuit opens and requests to it fail immediately, freeing threads for other work and stopping the cascade.
Bulkheads give each dependency a separate thread pool or semaphore. A slow database cannot exhaust the threads serving cache-hit requests.
Backpressure signals: when the app's queue is full, return 429 with Retry-After. Propagate this signal to upstream message queues (pause consumers) and to clients (which should respect retry budgets and use exponential backoff with jitter). Clients that retry unconditionally amplify the spike rather than dampening it.
9. Metrics and validation
Instrument these to know whether the design is working:
- Goodput rate: successful requests within SLO, not just total RPS. This is the number that matters.
- Shed rate by class: P0/P1/P2 shed separately. P0 shedding is a page.
- p50/p95/p99/p999 latency for admitted requests: confirm SLO is holding for what gets through.
- Concurrency limit over time: confirms the adaptive controller is tracking capacity.
- Queue depth and wait time per class: detects standing queues before they cause latency spikes.
- Circuit breaker state changes and fast-fail rate per dependency.
- Client retry rate: rising retries during a shed event signal clients are not honouring
Retry-After.
Run periodic load tests to verify the system sheds in the right order (P2 before P1 before P0) and that goodput plateaus rather than collapses as offered load climbs past capacity.
Common mistakes
- Setting a queue depth in absolute numbers without deriving it from the latency budget — you end up with a queue that guarantees SLO violations before it fills.
- Using only token buckets and assuming that covers overload — they do not account for server-side slowdowns.
- Forgetting deadline propagation across service calls, causing a downstream service to spend CPU on work the upstream caller already gave up on.
- No distinction between shed and error in client-facing responses, which makes dashboards and post-incident analysis much harder.