Serve some, not none
A flood: 16,000 req/s arrive, and six servers can answer 12,000. There's no time to add machines. Right now every request joins a long line, so even the ones that get an answer wait two seconds for it.
Play this levelPart of Bugpit Pro. It runs in your browser: build the design, press Run, and watch what breaks.
The lesson
When more arrives than you can handle, you choose who gets hurt. Do nothing, and requests line up inside your servers. The line grows, everyone waits, and people give up before their answer is ready. You did the work and nobody saw it.
Load shedding refuses the extra requests at the door, in a millisecond. Those users get an error or a simpler page. Everyone you do let in gets a fast answer.
Click **App Server** and tick **Shed load**. You'll still serve about 12,000 req/s, the same as before, but now they're answered quickly.
The same idea between your own services is called backpressure: a full queue tells the sender to slow down, instead of growing without limit until it runs out of memory.
What you have to achieve
16,000 requests a second at the busiest hour, 3% of them writes.
- No broken or illegal connections
- At least 11k req/s get an answer
- p99 response time under 300 ms
- Machines cost at most $1,300 / month
What you learn
The same 12,000 people are served, in a fraction of the time. Good shedding is also picky: keep checkout and login, drop recommendations and analytics first. An API gateway's rate limit is a fixed version of this; shedding reacts to how busy the server really is.
Check yourself
During a flood you can only answer 3 in 4 requests. Which should you drop first?
- Checkout
- Login
- "You might also like" suggestions
Show the answer
"You might also like" suggestions. Shed what people can live without. A page with no suggestions still works; a checkout that fails loses the sale.
A queue between two services has no size limit, and the reader is slower than the writer. What happens in the end?
- The queue grows until it runs out of memory or disk
- The writer slows down by itself
- Old jobs are answered first, so it's fine
Show the answer
The queue grows until it runs out of memory or disk. Nothing tells the writer to slow down. A bounded queue pushes back when it's full, which is what backpressure means.