Backpressure and load shedding
Overview
Every system has a maximum throughput. When more work arrives than it can handle, it must do something with the excess. The worst option, and the default if you don’t design for it, is to accept everything: queues grow, latency explodes, memory runs out and the service crashes, often repeatedly. Backpressure and load shedding are the deliberate alternatives.
Why unbounded queues fail
If requests arrive at 15,000 per second and the service can handle 10,000, an unbounded queue grows by 5,000 every second. Within a minute, each new request waits behind 300,000 others. Users gave up long ago, but the service is still doing their work: it’s busy, but producing nothing useful. Eventually it runs out of memory.
The rule: bound every queue, and decide what happens when it’s full.
Backpressure
Backpressure means pushing the problem back to the sender so it slows down:
- Blocking: a producer writing to a full bounded queue waits (common inside a process or between threads).
- Rejecting: the service returns 429 or 503 with
Retry-After; well-behaved clients back off. - Flow control: the receiver tells the sender how much it can accept (TCP windows, gRPC and reactive-streams credits).
- Consumer lag: in Kafka-style pipelines, the log absorbs the backlog durably; producers or upstream jobs check lag and slow down or pause.
Backpressure must propagate all the way to the source, or the pressure just builds somewhere else.
Load shedding
Sometimes you can’t slow the source (millions of users pressing refresh). Then shed load: reject some requests early so the rest are served well.
- Reject cheaply: decide at the edge or first thing in the service, before doing expensive work. A fast rejection costs microseconds; a timeout costs a thread for seconds.
- Use good signals: queue length, concurrency in flight, CPU, or latency (when p99 rises above target, start shedding). Adaptive concurrency limits adjust automatically, similar to TCP congestion control.
- Shed by priority: tag requests at the gateway (checkout > browsing > recommendations > analytics) and drop the lowest first. Within a priority, prefer keeping requests from users who are mid-session over brand-new ones.
- Drop stale work: if a queued request’s deadline has passed, skip it rather than process it.
Graceful degradation
Instead of rejecting outright, do less work per request:
- serve cached or static versions of pages,
- turn off expensive features (personalisation, related items, live counts),
- use cheaper algorithms (approximate search results),
- make non-critical writes asynchronous.
Feature flags that switch these modes on during incidents are invaluable.
Waiting rooms
For predictable extreme spikes (concert tickets, product drops), a virtual waiting room admits users to the protected flow at a fixed rate and shows everyone else their place in line. It turns an overload into an orderly queue with honest feedback.
Autoscaling isn’t enough
Autoscaling adds capacity in minutes; spikes arrive in seconds. It also can’t scale databases or third-party APIs. Shedding and backpressure hold the line while autoscaling catches up, and protect the parts that can’t scale at all.
In an interview
When discussing peaks or the “10× traffic” follow-up: “Queues are bounded; when they fill, the gateway sheds lowest-priority traffic first, recommendations and analytics, while checkout keeps its capacity. Pages degrade to cached versions, and for ticket on-sales we put a waiting room in front of checkout.”
Recap
When demand exceeds capacity, unbounded queues turn overload into crashes. Bound queues, use backpressure to slow senders, and shed load early, cheaply and by priority so that critical flows keep working. Degrade gracefully, use waiting rooms for known spikes, and don’t rely on autoscaling alone.
Black Friday overload
On Black Friday an online store receives 3× its tested capacity for 20 minutes. Traffic includes: checkout and payment, product pages, search, recommendations, and internal analytics events. The order service's queue grows without limit, memory runs out and it crashes and restarts repeatedly. Propose a plan using bounded queues, backpressure, load shedding and degradation, saying what users experience.
Bounded queues / backpressure:
Load shedding by priority:
Degradation:
What users experience:Bounded queues / backpressure:
- Give the order service a bounded in-memory queue and concurrency limit; when full,
reject new work quickly (503 + Retry-After) instead of buffering until it crashes.
- Asynchronous pipelines (analytics) use durable queues (Kafka/SQS); producers slow
down or drop analytics when lag grows.
Load shedding by priority:
- Tag requests by priority at the gateway: checkout/payment highest, product pages and
search next, recommendations and analytics lowest.
- As CPU/latency/queue thresholds are crossed, shed lowest-priority traffic first.
Degradation:
- Recommendations replaced by cached "popular" lists; search uses simpler, cheaper
queries; non-essential widgets hidden; static product data served from CDN/cache.
- A virtual waiting room in front of checkout if even that exceeds capacity.
What users experience:
Most users can still browse and buy, some see simpler pages or a short "please wait"
queue, and a few get a fast "try again" message - instead of everyone getting timeouts
and a repeatedly crashing site.Summary
- When demand exceeds capacity, unbounded queues only delay the failure and add latency; bound every queue.
- Backpressure signals upstream to slow down: blocking, rejecting, or flow-control credits.
- Load shedding deliberately rejects some work early so the rest succeeds; reject cheaply and quickly.
- Shed by priority: protect critical flows such as checkout and login, and drop optional work first.
- Combine with graceful degradation, waiting rooms and autoscaling, which is too slow to handle sudden spikes on its own.