Part 8 of 8 · 3 min read
Exercises
Easy
Easy 1: Requirements list (20 minutes)
Write seven requirements for a rate limiter from your own words, and three questions you would ask first.
Done when: seven rules and three questions exist, with two features marked out of scope.
Hint
Think about where it runs and what happens on failure.
Easy 2: Estimate the store (20 minutes)
A system has 2 million clients, 4 rules each, 80 bytes per counter, and 200,000 requests per second. One node does 50,000 operations per second. Give memory and node count.
Done when: you write 640 MB and at least 4 nodes, with the arithmetic.
Hint
2,000,000 × 4 × 80 bytes is 640,000,000 bytes.
Easy 3: Spot the leak (20 minutes)
A limit is 5 per minute. Client A sends 4 requests to limiter 1 and 4 to limiter 2 in one minute with private counters. How many pass? With a shared store?
Done when: you write 8 and 5, and name the problem as synchronisation.
Hint
Each limiter sees only 4, so both pass all of theirs.
Medium
Medium 1: Race by hand (30 minutes)
Counter is 9 with limit 10. Three requests arrive together. Show the outcome with read-check-write steps, then with an atomic increment.
Done when: one table shows 3 passing and a final count of 10 in the broken case, and 1 passing in the atomic case.
Hint
Three reads of 9 all see room for one more.
Medium 2: Choose a method (30 minutes)
For a login form, a public read API and a billing job, pick a method and a failure mode (open or closed). Give one reason each.
Done when: three rows with method, fail mode and reason.
Hint
A login form guards against password guessing.
Medium 3: Draw it (30 minutes)
Draw the full design with gateway, rules cache, store shards and replicas, and mark where the 429 is made and where failure falls back.
Done when: a diagram with at least six labelled parts and two arrows for the failure path.
Hint
The 429 comes from the middleware, not the store.
Hard
Hard 1: Three regions (60 minutes)
Design the three-region follow-up. State how limits are shared, how often they sync, the worst overshoot, and what happens if a region loses contact.
Done when: a page with numbers for sync interval and worst-case overshoot, and a rule for a cut-off region.
Hint
Give each region a share of the limit that moves with traffic.
Hard 2: Cut the store load (60 minutes)
With 500,000 requests per second, design a local counter that syncs every 200 ms. Give the new store load and the worst-case error per client.
Done when: you compute the store load with 100 limiters, and state the error as a number of requests.
Hint
Divide requests by the number of sync intervals per second.
Hard 3: Mock interview (60 minutes)
Answer "design a rate limiter" aloud in 35 minutes, record it, and mark yourself on the four steps. List two things missed.
Done when: a recording, a score on each step, and two named gaps.
Hint
Use the four-step framework as a checklist.