Phase 7
Design Problems
Apply what you learned. Each problem has a suggested focus — practice walking through requirements, estimation, and high-level design.
Don't just read. Pause, think through each step, then compare. Practice on a whiteboard or paper. Time yourself (30–45 min). For each problem: clarify → estimate → data model → high-level → deep dive on 1–2 areas.
URL Shortener
Requirements: Create short URL, redirect, optional expiry. Analytics optional.
Estimation: 100M URLs/month, 100:1 read:write → 40 writes/s, 4K reads/s. 12B records × 500B ≈ 6 TB over 10 years. Cache 20% → ~35 GB/day.
Key generation: Base62 (62^7 ≈ 3.5T URLs). Hash (MD5) → collision risk. Counter + Base62 → SPOF. KGS: pre-generate keys in DB; move used keys to separate table with locking. Zookeeper-style ranges for distributed counters.
Flow: Create → KGS gives key → write DB + cache → 201. Redirect → cache hit → 301; miss → DB → 301 or 404. Sharding by hash; LRU cache. Cleanup: active (cron) or passive (on access).
Rate Limiter
Focus: Token bucket, sliding window. Per-user or per-IP. Distributed: Redis with atomic ops; avoid get-then-set race. Return 429 when limit exceeded.
Design a Cache
Focus: LRU eviction, capacity, concurrency. Distributed: consistent hashing for sharding. Replication for durability. Cache-aside vs write-through.
Practice checklist
Work through these in order. For each: set a 40-min timer, clarify requirements, estimate, design, then review.
- URL Shortener
- WhatsApp / Messaging
- Twitter / Newsfeed
- Netflix / Video Streaming
- Uber / Ride Matching