LS·207
Phase 11 — System Design
The eleventh phase: the system-design method (requirements, estimation, architecture, data, APIs, scaling, consistency, reliability, trade-offs) practised on five simple systems (URL shortener, rate limiter, file storage, notification service, chat) and then eight harder ones (ticket booking, payments, collaborative editing, ride matching, social feed, search, recommendation, multi-tenant SaaS); the order and why, an entry check, step-by-step exit checks mapped to Volumes 12 and 13, the design portfolio with definitions of done, traps, a time budget, and a lab that checks two classic back-of-the-envelope estimates against simulation and Redis.
Start here: Phase 11 in one page
Phases 1–10 taught you the parts. Phase 11 teaches you to combine them on paper before building: take a vague requirement ("a URL shortener"), turn it into numbers, choose an architecture, data model and APIs, and defend every trade-off. Interviews test this, but so does every real project's first week.
The method, used for every design
requirements → estimation → architecture → data model → APIs → caching → sharding → consistency → reliability → trade-offs
This is the order of a design conversation. Requirements and numbers come before boxes, because they decide which boxes you need; the data model and APIs before scaling tactics; trade-offs last, because they're about comparing the whole.
The designs, simple first
| Tier | System | The new difficulty it adds |
|---|---|---|
| start | URL shortener | read-heavy traffic, ID generation, caching |
| start | rate limiter | counting across many servers, algorithms (token bucket, sliding window) |
| start | file storage | large blobs, metadata vs content, chunking, presigned uploads |
| start | notification service | fan-out to channels, retries, preferences, deduplication |
| start | chat | persistent connections, ordering, presence, delivery receipts |
| then | ticket booking | contention for scarce items, holds, double-booking prevention |
| then | payments | exactly-once effects, idempotency keys, ledgers, reconciliation |
| then | collaborative editing | concurrent edits: operational transforms or CRDTs |
| then | ride matching | geospatial indexing, real-time location updates, matching |
| then | social feed | fan-out on write vs read, celebrity accounts, ranking |
| then | search | inverted indexes, ingestion pipelines, relevance |
| then | recommendation | candidate generation and ranking, offline vs online features |
| then | multi-tenant SaaS | isolation, noisy neighbours, per-tenant limits and data residency |
The simple five teach the method on familiar ground; each of the harder eight forces one hard idea you haven't needed yet.
Estimates you can check
The lab tested two estimates every URL-shortener design makes:
| Question | Estimate | Measured |
|---|---|---|
| random 7-character base62 codes: chance of any collision among 1 million URLs? | birthday bound ≈ 13% | 13.2% (formula) and a simulation with 5-character codes matched the formula (6.6 vs 5.5 expected collisions) |
| with Zipf-like popularity, what share of reads does a cache of the top 1% of URLs serve? | "most of them" | 75.5% (59.7% at 0.1%, 84.2% at 5%) |
| how fast is one Redis instance for lookups? | ~100k ops/s | 113k GET/s (p50 0.22 ms); 1.96M/s with pipelining |
So: generate codes with a collision check (or a counter), cache a small hot set, and one Redis instance serves far more redirects than most shorteners will ever see.
How deep to go in Phase 11
Volume 17 defines six mastery levels; Phase 11's exit targets are:
| Topic | Exit level | What that means here |
|---|---|---|
| requirements and estimation | L3 | turn a brief into numbers in five minutes |
| architecture, data model, APIs | L4–L5 | choose and justify for every design in the portfolio |
| caching, sharding, consistency | L4 | pick strategies, explain failure modes |
| reliability | L4 | failure modes, redundancy, degradation |
| trade-offs | L5 | defend alternatives with numbers |
The sequence, step by step
| Step | Learn | Read | Exit check |
|---|---|---|---|
| 1 | requirements and estimation | Vol. 12, Start Here, ch. 121–122 | numbers for the five simple systems |
| 2 | building blocks, scaling, availability | Vol. 12, ch. 123–125 | design the URL shortener and rate limiter |
| 3 | caching, databases, messaging | Vol. 12, ch. 126–128 | design file storage and the notification service |
| 4 | consistency, reliability, events, APIs | Vol. 12, ch. 129–132 | design chat; then ticket booking and payments |
| 5 | multi-tenancy and global systems | Vol. 12, ch. 133–134 | design multi-tenant SaaS |
| 6 | worked case studies | Vol. 12, Case Studies | compare your designs with the worked ones |
| 7 | architecture: DDD, styles, decisions | Vol. 13, ch. 138–142 | a bounded-context map and an ADR for one design |
| 8 | the remaining designs and practice | Vol. 12, ch. 135 | collaborative editing, ride matching, feed, search, recommendation; two mock interviews |
Entry check
Phases 3–10: you've built most of the components you'll be drawing.
The phase project: a design portfolio
Goal. Thirteen written designs (the five simple systems, then the eight harder ones), each defensible in a 45-minute conversation.
Milestones per design. Requirements (functional, non-functional, out of scope) → estimates (traffic, storage, bandwidth, peaks) → high-level architecture → data model → APIs → deep dives on the two hardest parts → failure modes → trade-offs and alternatives → what changes at 10× scale.
Done when. Each design fits on two pages plus a diagram (the simple five can be one page); every number has a derivation; every choice names its rejected alternative; you've presented two designs to someone who asked hard questions; one estimate per design is checked against a benchmark or a published figure.
Stretch. Build the URL shortener for real and load-test it against your estimates.
Common traps
- Boxes before requirements.
- Scaling everything: sharding a system that fits on one machine.
- Naming technologies instead of reasoning ("use Kafka").
- Ignoring failure modes and operations.
- No numbers.
Exit criteria
- [ ] The portfolio meets its "done when" list for all thirteen systems.
- [ ] I can estimate traffic and storage quickly and sanity-check results.
- [ ] I can explain caching, sharding and consistency choices with failure modes.
- [ ] I passed two mock design interviews.
- [ ] I scored at least 80% on 40 questions from Volumes 12–13's quizzes, twice.
Time budget
Volumes 12 and 13 (about 160,000 words) are about 11.5 hours of reading; with practice, about 46 hours, plus 6 weeks for the portfolio (about 2 hours per simple design and 4–5 per hard one): about 3 months at 8 hours a week.
Lab: checking back-of-the-envelope estimates
Setup. Python with NumPy for the collision and cache simulations, and redis-benchmark against a local Redis 7 on the lab machine.
Experiment 1: code collisions
Random base62 codes of length k give 62^k possible codes. The birthday approximation for the chance of at least one collision among n codes is 1 − e^(−n²/(2·62^k)):
| Codes | 100,000 URLs | 1 million | 10 million |
|---|---|---|---|
| 7 characters (3.5 × 10¹² codes) | 0.0014 | 0.132 | ≈ 1.0 |
To check the formula, a simulation with 5-character codes (9.2 × 10⁸) and 100,000 URLs, averaged over 20 trials, found 6.6 collisions against 5.5 predicted by n²/(2N): close, given that 20 trials of a rare event leave a wide margin. Lesson: at real scale, collisions will happen; check on insert (unique constraint and retry) or use a counter encoded in base62.
Experiment 2: how much a small cache serves
1 million URLs with Zipf(1.1) popularity (2 million draws, keeping those that fall within the 1 million URLs), replayed through an LRU cache:
| Cache size (share of URLs) | Hit rate |
|---|---|
| 0.1% (1,000) | 59.7% |
| 1% (10,000) | 75.5% |
| 5% (50,000) | 84.2% |
Popularity skew is why caches work; the exponent matters, so measure your real distribution before sizing.
Experiment 3: one Redis instance
redis-benchmark on the lab machine, 50 clients:
| Operation | Throughput | Median latency |
|---|---|---|
| SET | 122,850/s | ~0.22 ms |
| GET | 113,250/s | ~0.22 ms |
| GET, pipelined ×16 | 1.96 million/s | — |
Loopback on one machine flatters latency; across a network add ~0.1–0.5 ms. Even so, one instance covers ~100× the average load of a shortener with 100 million redirects a day.
Try it yourself
- Change the Zipf exponent to 0.8 and 1.3 and redo the cache table.
- Estimate storage for 5 years of a shortener at 100M new URLs per month, then check with a real table of a million rows in PostgreSQL.
- Benchmark your own API's redirect endpoint with and without Redis.
Revision sheet: Phase 11, system design
Key ideas
- Sequence: requirements → estimation → architecture → data model → APIs → caching → sharding → consistency → reliability → trade-offs.
- Numbers first; every choice names the alternative it beat.
- Practise five simple systems (URL shortener, rate limiter, file storage, notification service, chat), then eight harder ones (ticket booking, payments, collaborative editing, ride matching, social feed, search, recommendation, multi-tenant SaaS), each adding one new difficulty.
Numbers to remember
- 1 day ≈ 86,400 s ≈ 10⁵ s; 1M/day ≈ 12/s.
- 7-char base62: 3.5 × 10¹² codes; 13% collision chance at 1M URLs.
- Zipf(1.1): a 1% cache served 75.5% of reads.
- Redis: ~110–120k ops/s per instance, ~2M with pipelining (lab).
- Budget: ~46 study hours + 6 portfolio weeks ≈ 3 months at 8 h/week.
Pitfalls
- Architecture before requirements; technology name-dropping.
- Over-scaling; ignoring operations and failure.
Glossary
- Back-of-the-envelope estimate: a quick order-of-magnitude calculation.
- Birthday bound: collisions become likely around √N items.
- Fan-out: delivering one event to many recipients.
- Sharding: splitting data across nodes by key.
- ADR: architecture decision record.