Lessons › From one user to millions
CDN, queues and no single point of failure
30,000 req/s. Half are images and scripts, and writes trigger slow work like emails. Nothing may go down if one machine dies.
Play this levelFree with an account. It runs in your browser: build the design, press Run, and watch what breaks.
The lesson
A CDN serves static files from servers near the user. Those requests never reach your data centre, and users get them in ~10 ms (§7.4). It saves servers and time, but it isn't free: you pay for every request and GB.
A Queue lets the app answer right away and hand slow work to Workers in the background. Add enough workers or the backlog keeps growing (§9).
A single point of failure (SPOF) is any component that takes the whole system down when it dies. Run at least 2 of each, and give the database a standby (§10.2).
What you have to achieve
30,000 requests a second at the busiest hour, 5% of them writes and 50% static files.
- No broken or illegal connections
- Use a CDN
- Use a Queue
- No component is overloaded
- Workers clear the queue within the day
- No single point of failure
- Fewer than 0.1% of requests fail
- p99 response time under 250 ms
- Machines cost at most $2,900 / month
What you learn
This is the classic Stage 4 architecture. Open "A day of traffic" to see the queue fill at the evening peak and empty overnight, which is why you need fewer workers than the peak suggests.
Check yourself
Sending an email after a write was slow. What fixed it?
- A queue and workers in the background
- A bigger app server
- A read replica
Show the answer
A queue and workers in the background. The app answers straight away and hands the slow work to workers. You need enough workers or the backlog grows.
What is a single point of failure?
- The slowest part of the design
- The most expensive part
- A part that takes everything down when it dies
Show the answer
A part that takes everything down when it dies. Run at least 2 of each part, and give the database a standby, so no one machine can take the system down.