Cloud
Load Shedding
Sorting the current batch of requests by priority takes O(n log n) time for n requests. Deciding what to keep is then a simple O(n) scan. The payoff is stability: a system that sheds load stays responsive, while one that doesn't can fall over completely.
The idea, in plain English
Think of a busy hospital emergency room on a chaotic night. The ER doesn't treat people in the order they walked in. It treats the most critical cases first, and if it's completely overwhelmed, patients with minor issues have to wait or go elsewhere. Load shedding works the same way for a computer system. When too many requests arrive at once, the system doesn't try to handle every single one and risk crashing. It sorts them by priority and deliberately drops the low-priority ones — this is called 'shedding' — so the truly important work still gets done.
How it works
- 1Give every incoming request a priority — for example, critical, normal, or low.
- 2Compare how many requests just arrived to how much the system can actually handle at once, called its capacity.
- 3If there's room for everyone, serve them all. No shedding needed.
- 4If there isn't enough room, sort by priority and serve only as many as fit, starting with the most critical. Drop the rest, instead of letting everyone slow down or the whole system crash.
When you'd use it
Use this for any system that can get hit with more traffic than it can safely process — a ticket site during a big sale, a search system during a traffic spike. It's better to fully serve the most important requests and reject the rest than to accept everything, serve every request badly, or crash entirely.
Common beginner mistakes
- Treating every request as equal priority. Then shedding is basically random, and you might drop a checkout request while keeping a background image load.
- Never shedding anything and hoping the system can 'just handle it.' An overloaded system with no shedding often ends up serving nobody well, or crashing outright.
- Shedding too aggressively and dropping requests the system actually had capacity for.
Try it — edit and run
Click the code to edit · press ⌘/Ctrl+↵ to run
Editable code. Tab and Shift+Tab indent. Press Escape, then Tab, to move focus out of the editor.
Tick 1: 3 requests in, capacity 3 -> served: r1, r2, r3; shed (dropped): none
Tick 2: 4 requests in, capacity 3 -> served: r5, r6, r4; shed (dropped): r7
Tick 3: 4 requests in, capacity 3 -> served: r8, r9, r10; shed (dropped): r11
Summary: 9 requests served, 2 requests shed across 3 ticksNot sure this is the right topic? See the learning paths → or where this leads →