Designing a service end to end
Three step-by-step designs, as in a system design interview: a URL shortener, a news feed, a messenger. For each: requirements, worked back-of-the-envelope numbers, the API, storage, scaling and failures, with the reasoning on the back.
- 34 cards
- 3 topics
- Free
The outline, topic by topic
Each topic is weighted the way the exam weighs it.
- A URL shortener
- A news feed
- An instant messenger
A few cards from the deck
Requirements · What are the two essential operations of a URL shortener?
Show the answer
Create a short link for a long address, and redirect a short link to its long address
Redirects far outnumber creations: often 100 reads per write, which shapes the whole design.
Back-of-the-envelope · 100 million links created per month: how many creations per second on average?
- About 4
- About 400
- About 4,000
- About 40
Show the answer
About 40
100,000,000 ÷ (30 × 86,400 s) ≈ 39 per second.
Failure · How do you stop the service being used to spread malicious links?
Show the answer
Check addresses against malicious site lists and rate-limit creation per account
Checking blocks known links; rate limiting stops thousands of links being created at once.
Back-of-the-envelope · With 100 reads per write and about 40 creations per second, how many redirects per second?
- About 40
- About 400
- About 4,000
- About 400,000
Show the answer
About 4,000
40 × 100 = 4,000 redirects per second on average, and more at peak.
Requirements · What must a news feed do, at the very least?
Show the answer
Post a message, and show everyone the recent messages of the accounts they follow
The whole challenge is building, quickly and for millions of people, a feed specific to each.
Back-of-the-envelope · Links are kept 5 years, at about 500 bytes each. How much storage?
- About 3 GB
- About 300 GB
- About 3 TB
- About 300 TB
Show the answer
About 3 TB
100 million × 12 × 5 = 6 billion links; × 500 bytes = 3 × 10¹² bytes, or 3 TB.