Final challenge: run a small web shop on several servers
After this: Size a group of servers, predict round robin, find the failed requests and keep the servers stateless.
This challenge has five steps, and each step is scored on its own. You will work out how many servers a busy site needs, predict how round robin shares ten requests, find the requests a crashed server costs, make a shop's servers stateless, and choose a plan that survives a crash. The one program shows Python and Java; its output is the same in both. You can try as many times as you like, and hints work as they do in the lessons.
Step 1 of 5How many servers
How many servers
A ticket site expects 3,000 requests per second at its busiest. Its servers do more work per request than the shop's: each handles 250 per second. How many servers should it run, with one spare?
Predict it
This program counts how many of ten requests each of three servers gets under round robin. What does it print?
counts = [0, 0, 0]for i in range(10): turn = i % 3 counts[turn] = counts[turn] + 1print(counts[0], counts[1], counts[2])public class Main { public static void main(String[] args) { int[] counts = new int[3]; for (int i = 0; i < 10; i++) { int turn = i % 3; counts[turn] = counts[turn] + 1; } System.out.println(counts[0] + " " + counts[1] + " " + counts[2]); }}Find the failures
Servers A, B and C take turns, starting at A. Six requests arrive, and a health check runs after requests 3 and 6. Server A crashes right after request 1. How many of the six requests fail?
Make it stateless
Each of the shop's servers keeps a dictionary (a map in Java) from session id to cart in its own memory. Which change lets any server answer any request, and lets a server crash without losing a cart?
Choose the plan
The shop expects 1,000 requests per second, and each server handles 400. Which plan keeps up when one server dies and loses no carts?
- Size a group of servers with a spare, predict how round robin shares requests, find the requests a crash costs, make servers stateless, and choose a plan that survives a crash.