A service handles checkout, search and background prefetch on the same fleet, and it is overloaded. How do you decide what to shed?
Sketch your own answer first, then compare it with the one below.
A strong answer
Shed by importance, not at random. Give each request a criticality when it enters the system, and carry it with the request through every hop. Under overload, the service first rejects the least critical class, then the next, and keeps the most critical class until the very end.
Make the signal that triggers shedding something that tracks the real problem. Queue delay, concurrency in flight, or CPU are better than request rate, because requests differ in cost. Take care with a metric that feeds back on itself: if shedding lowers it, shedding stops, load returns and it starts again. Use some hysteresis.
Do it at the cheapest point, which is as early as possible and before expensive work. Let the callers help. If a caller sees many rejections from a backend, it can throttle itself on the client side, so most of the rejected traffic never leaves it.
Plan for the sum of retries too. Rejected clients that retry add load, so use Retry-After, backoff, and retry budgets.
Test it the way it fails: replay a load spike in staging and check that checkout survives while prefetch is the first thing to go.
Sources
- Betsy Beyer, Chris Jones, Jennifer Petoff, Niall Richard Murphy (2016). Site Reliability Engineering, chapter 21, Handling Overload.
- Matt Welsh, David Culler, Eric Brewer (2001). SEDA, an architecture for well-conditioned, scalable internet services.