Part 7 of 7 · 3 min read
Exercises
Easy
Easy 1: Walk the path (20 minutes)
List the layers a request passes from a browser to a database in a shop. For each layer write what it holds and whether it is shared between users.
Done when: a table with at least five layers.
Hint
Start at the user and end at the disk.
Easy 2: Choose headers (20 minutes)
Choose a Cache-Control rule for: a logo, a script file named with a hash, the user's order history page, a news front page.
Done when: four rules with a reason each.
Hint
Versioned names can have very long lifetimes. Personal pages must not be shared.
Easy 3: 304 or 200 (20 minutes)
A client holds ETag "a1" for a file. The server's current ETag is "a1" in one case and "b2" in the other. Write the request and the response in each case.
Done when: two request-response pairs.
Hint
A match gives 304 with no body. A mismatch gives 200 with a new ETag.
Medium
Medium 1: Requests reaching the database (30 minutes)
500,000 requests meet a browser hit ratio of 30 percent, a CDN of 60 percent, a shared cache of 85 percent. How many reach the database? How many if the CDN is removed?
Done when: two counts and the ratio between them.
Hint
Multiply the requests by each miss ratio.
Medium 2: Worst-case staleness (30 minutes)
TTLs: browser 90 seconds, CDN 300 seconds, shared cache 600 seconds. Compute the worst-case age. After a write the server deletes the shared cache key and purges the CDN. What is the worst case now?
Done when: two figures with the working.
Hint
Add the TTLs. After purging, only the browser TTL remains.
Medium 3: Bytes saved (30 minutes)
A script file is 250 KB and is loaded 10 times per user per week. Compute weekly bytes per user with no caching, with a one-week max-age, and with ETag only (a 304 reply is 400 bytes). Count round trips for each.
Done when: three byte totals and three round-trip counts.
Hint
With ETag only, there are 10 round trips each week, with one full download.
Hard
Hard 1: Latency through the layers (45 minutes)
Using the structure of section 3, compute the average latency for 100,000 requests with your own hit ratios and times. Then raise the browser hit ratio by 10 points and recompute. Explain which change has the larger effect and why.
Done when: two averages, the table, and an explanation.
Hint
Weight each layer's latency by the share of requests it answers.
Hard 2: Design the caching of a news site (50 minutes)
A news site has article pages (change in the first hour), images (never change), a home page (changes every minute) and a user account page. For each, choose layers, TTLs, purge rules and the worst-case staleness. State what happens during a database outage.
Done when: a four-row table and an outage plan.
Hint
Different data needs different rules, so use one row each.
Hard 3: Cut a layer (50 minutes)
A design has five cache layers and the team suspects two are not worth it. Using hit ratios you choose, compute the load reaching the database with all five layers, and with each of the two removed in turn. Decide using the database limit of 1,500 reads a second at a traffic of 40,000 requests a second.
Done when: three database loads, a decision and the complexity saved.
Hint
Database load = requests × product of the miss ratios.