Part 8 of 8 · 3 min read
Exercises
Easy
Easy 1: Write the patterns (20 minutes)
A to-do app has users, lists and tasks. Write five access patterns, each with the kind, a made-up rate and what it needs.
Done when: a table of five rows with the four columns.
Hint
Include the kind (read or write), the field it is found by and the sort.
Easy 2: Spot the rule (20 minutes)
For each case say whether a transaction is needed: liking a post, booking the last seat on a flight, adding a profile photo, moving stock between two warehouses, counting a page view.
Done when: five answers, each with a reason and the harm if the rule fails.
Hint
Ask "what if the server dies halfway?".
Easy 3: One node or not (20 minutes)
A node handles 6,000 writes and 15,000 reads per second. A feature needs 2,500 writes and 30,000 reads. Is one node enough? What is the smallest fix?
Done when: a verdict for writes, a verdict for reads and one fix with its effect.
Hint
Check writes and reads separately.
Medium
Medium 1: A cache or a NoSQL store (30 minutes)
Reads are 50,000 per second and the node handles 12,000. Compute the hit ratio needed for a cache to bring the database below 70 percent of its capacity. Then compute the number of read copies needed instead, with no cache.
Done when: a hit ratio in percent, a number of copies and a comparison of the two options.
Hint
Needed database reads = reads × (1 − hit ratio).
Medium 2: The transfer, replayed (30 minutes)
Write the steps of a transfer of 250 between two accounts for a store with single-record writes only. Add a log of intended steps so that a crash can be repaired. Show the state after a crash between steps and the repair.
Done when: a numbered sequence, a log format, a crash table and the repair steps.
Hint
Write the intent to the log first, then do the steps, then mark done.
Medium 3: Choose for six systems (30 minutes)
Choose a model and an example product for: a forum, a ride location tracker, a library catalogue, a game leaderboard, a ticket booking site and a log archive. Give the key access pattern for each.
Done when: six rows with a choice, the access pattern and the main cost.
Hint
Start from the main question for each system.
Hard
Hard 1: Size and decide (45 minutes)
A messaging app has 20 million daily users, each sending 40 messages a day. A message is 300 bytes. Compute writes per second (average and a peak of 3 times the average), storage per day and per year. Choose the store, the key design and the read pattern, and state what is given up.
Done when: four numbers with the working, a choice, a key and a trade-off.
Hint
Messages per day divided by 86,400 gives the average per second.
Hard 2: Two stores in step (45 minutes)
A shop keeps orders in a relational database and product views in a key-value store. Design how a "popular products" page uses both. Say what can be out of date, by how long, and how a user would notice.
Done when: a flow, an out-of-date window in seconds, and the user-visible effect.
Hint
Think about a counter that is updated in batches.
Hard 3: Defend a bad-looking choice (50 minutes)
A start-up with 5,000 users picks one relational database for everything, including logs and counters. A colleague says it will not scale. Estimate the load at 100 times the users. Argue for keeping it, then name the first two parts you would move and the trigger for each.
Done when: an estimate of load, an argument and two triggers with measurable thresholds.
Hint
Multiply the load, compare it with the node's capacity, and pick the thing that breaks first.