Part 8 of 8 · 4 min read
Exercises
Easy
Easy 1: Find the state (20 minutes)
List the state in each case and say where it lives now: a cart kept in a server's memory, a login in a cookie with a random id, a signed token, a profile picture on a server's disk.
Done when: four rows with the state, its current place from the table in section 1, and whether the design is stateless.
Hint
Ask "if this server vanished, what is lost?".
Easy 2: Size the store (20 minutes)
A site has 500,000 logged-in users at the peak. Each session record is 2 KB. Find the memory needed, and the lookups per second if there are 8,000 requests per second.
Done when: a memory figure in GB, a lookup rate and one sentence on whether one node can do it.
Hint
Users × size = memory. One lookup per request.
Easy 3: Cookie flags (20 minutes)
Explain in one sentence each what HttpOnly, Secure and SameSite do, and name an attack each one makes harder.
Done when: three sentences, each with a named risk.
Hint
Think of scripts reading cookies, plain-text networks and forged requests from other sites.
Medium
Medium 1: Stolen token (30 minutes)
An access token lasts 20 minutes, and a refresh token lasts 14 days. A token is stolen at the 12th minute of its life, and the owner blocks the refresh token 6 minutes later. How long is the thief able to act? Redo it with a 5-minute access token that is stolen 3 minutes into its life, and the same 6 minutes before the refresh token is blocked.
Done when: two exposure times in minutes, with the timeline, and the cost of the shorter life.
Hint
The thief can act until the access token expires. A blocked refresh token only stops renewal after that.
Medium 2: Sticky or not (30 minutes)
Six servers each hold 1,500 stickily placed users. One server fails and its users go to a single other server. Compute the load on that server before and after. Then compute the load if the balancer spreads them evenly over the five that remain.
Done when: three loads in users per server and a comment on which is better.
Hint
1,500 + 1,500 = 3,000 on one server. Spread: 1,500 ÷ 5 each extra.
Medium 3: Autoscaling saving (30 minutes)
A stateless service needs 20 servers for 3 hours a day and 5 servers for the other 21 hours (both counts include the spare). Compute the average number of servers per day, and the saving against keeping 20 all day.
Done when: an average, a saving in servers and in percent, with the sums shown.
Hint
Average = (20 × 3 + 5 × 21) ÷ 24.
Hard
Hard 1: Make a service stateless (45 minutes)
A photo-sharing service keeps sessions in memory, stores uploads on local disks, runs a nightly clean-up job on every server and counts page views in a local variable. Write the migration plan, one step per problem, with the new home of each, and the order of the steps.
Done when: a plan of at least four steps with an order, a risk for each step and a check that it worked.
Hint
Move the things that lose data first, and the things that run twice next.
Hard 2: Token or session (45 minutes)
A company has a web app, a mobile app and 12 internal services, in 3 regions. Choose between sessions and signed tokens for the end users. State the revocation plan, the refresh plan, and where the login check happens. Defend the choice against the other option.
Done when: a decision, a revocation and a refresh plan, and a paragraph that names the main risk of the choice.
Hint
Many services in many regions favour a check that needs no shared lookup.
Hard 3: Reconnect storm (50 minutes)
A chat system has 8 servers and 4 million connected users. One server fails at peak. Work out the reconnections per server and per second for a random delay of 10, 30 and 60 seconds. Pick one and explain the trade-off for users.
Done when: a table with three rows, a pick, and a note on what a user feels with a 60-second delay.
Hint
Users per server = 4,000,000 ÷ 8. Rate = users to move ÷ delay.