Video in progress

Your service suddenly got 5 times the traffic and started to fall over. How do you make the system degrade gracefully under load with backpressure and load shedding?

An overloaded service is better off rejecting the excess immediately than serving every request slowly: bounded queues, a limit on concurrent requests, dropping requests whose deadline has passed, and priority for critical traffic. The load is pushed back to the source (backpressure), which slows down.

📖 Answer

The typical failure mechanism: requests arrive faster than they get processed. The queue (thread pool, Tomcat accept queue, connection pool wait) grows. Latency goes from 200 ms to 20 s. The client times out at 5 s and retries — while the server is still processing a request that was already abandoned. As a result the server is 100% busy but useful work is close to zero. This is "goodput collapse".

What I do:

Bounded queues. An unbounded LinkedBlockingQueue is a hidden bomb. If the queue is full — immediately a 503, not waiting.

Concurrency limit. The number of requests processed at once, say 200. A static number or an adaptive one (Netflix's concurrency-limits library finds the limit itself based on latency changes).

Deadline. The client passes the deadline in a header (it's natural in gRPC). If a request that comes off the queue has already expired, drop it without processing — nobody is waiting for the answer.

Priority. Not all requests are equal. Payment confirmation and login are high; recommendations, analytics and "similar products" are low. When load rises, the low-priority ones are rejected first. It's set at the gateway by header or by endpoint.

Graceful degradation. Instead of personal recommendations, a general top from the cache; instead of real-time stock, "in stock"; fewer results in search. Turned off by hand or automatically through a feature flag.

Backpressure also works along the chain. A Kafka consumer reads at its own pace — that's natural backpressure, lag grows but nothing falls over. In reactive streams it's request(n). In synchronous HTTP the backpressure signal is 429/503 and Retry-After; clients must respect it and work with a retry budget.

Autoscaling doesn't replace this: new pods arrive in 1–2 minutes, and the DB doesn't scale out at all. Shedding is needed to get through the first two minutes.

And test this ahead of time: in a load test, apply 2x, 5x, 10x and see how latency and the error rate change. In a good system, even at 5x the number of successful requests doesn't collapse, only the excess is rejected quickly.