Black Friday, worldwide
A shop with customers in America, Europe and Asia. On Black Friday 30,000 req/s arrive, half of them images, and everything runs in one region in Virginia. The board has one question: what happens if that region goes dark mid-sale?
Play this levelPart of Bugpit Pro. It runs in your browser: build the design, press Run, and watch what breaks.
The lesson
Start with distance. Run the app in three regions, close to each group of customers, with a cache in each so product pages stay local.
A crowd this size needs a waiting room in front, set to what your servers can really take. Nobody gets an error, they wait a moment instead.
Orders are the only writes, and there's only one primary. Put them in a queue so a customer in Tokyo isn't waiting on Virginia, and let workers save them.
Then the big one: a whole region failing. Each region needs enough servers to cover for a lost one, and a replica somewhere else that can become the primary.
What you have to achieve
30,000 requests a second at the busiest hour, 1% of them writes and 50% static files.
- No broken or illegal connections
- Use a CDN
- Use a Waiting Room
- Use a Queue
- No component is overloaded
- Workers clear the queue within the day
- After the home region goes dark and a replica takes over, under 1% of requests fail
- Fewer than 0.1% of requests fail
- p99 response time under 300 ms
What you learn
Lose Virginia mid-sale and the other two regions carry on. Look at the bill, though: you're paying for a third more servers than a normal day needs, just in case. Running in several regions is insurance, and like any insurance, someone has to decide it's worth it.
Check yourself
Why do orders go through a queue in a worldwide shop?
- Queues are cheaper
- There's one primary, and nobody should wait on a database across the world
- Orders need to be sorted
Show the answer
There's one primary, and nobody should wait on a database across the world. The order is taken locally and saved in the background.
With 3 regions, how many servers must each region have?
- A third of what you need
- Exactly what it needs
- Enough to cover for a lost region
Show the answer
Enough to cover for a lost region. If one region goes dark, the other two carry everyone. That spare capacity is the price of the insurance.