System design interview preparation
Design a URL shortener
Design a URL shortener with durable links and fast redirects. Work through reads, cache misses and traffic spikes, then play the matching problem.
Play the matching problemSeparate creating a link from following it
A URL shortener saves a long web address under a short code. Creating the link writes the mapping. Following the short link reads that mapping and returns a redirect. The two paths have different jobs: creation must preserve the record, while redirects must stay quick when many people open the same link. In this scenario, links do not change and reads dominate. Start by explaining those two paths before choosing any services.
Choose where the original mapping lives
A cache is a copy that can disappear. It cannot be the only place a new link is saved. Write the mapping to durable storage before telling the caller that creation succeeded. A key-value store fits the lookup by short code. Explain how you would allocate codes, detect a collision and retry safely. Those are design questions to reason through. Drawing a storage box alone does not prove them.
Estimate the work after a cache miss
Use the request mix below to separate writes from reads. For the read path, estimate how many requests reach the original store after caching. Then repeat the estimate with an empty cache. A design sized only for a warm cache can fail when the same popular link suddenly needs to be fetched again by many callers. Combining concurrent misses avoids asking the store the same question repeatedly.
Test one decision at a time
Build a baseline in the game and predict the first bottleneck. Run the full day before changing the design. Compare successful requests, response time, data safety and monthly cost. Change the cache policy or capacity, then repeat the same workload. Explain both the improvement and its cost. A redirect that is fast in one run still needs a clear argument for keeping a newly created mapping after a failure.
The matching game brief
People paste a long web address and get back a short one. Millions of other people then tap that short link, so reading is almost everything. Keep every tap fast, and never lose a link.
- Who uses it
- 50 million people a month
- Audience in plain numbers
- 50,000,000 people per month
- Normal peak
- ≈ 5,000 requests per second
- Request mix
- Read: 99%; Write: 1%
- Speed for 99 of 100 requests
- Read: ≈ 200 ms; Write: ≈ 200 ms
- Successful requests
- 99.9%
- Data safety
- No acknowledged write may be lost.
- Monthly budget
- ≈ $12,000
- Data at rest
- ≈ 1.5 TB
- Where users are
- North America: 70%; Europe: 30%
- Home region
- North America
- Waiting deadlines
- Read: 900 seconds; Write: 3,600 seconds
≈ marks an approximation, just as in the game. Waiting deadlines measure the age of queued work and are separate from interactive response time.
- Short codes are 7 characters. Each stored link uses about 0.5 KB including its metadata (approx.).
- About 20 new links a second on average (≈ 50 million a month, approx.).
- One app server handles about 1,000 requests a second (approx.).
Play the url shortener problem or read the full problem and clarification answers.
Playing on systemdesigner.io needs a free Google or GitHub account. These pages, the lessons and the guides can be read without one. Figures in the game are teaching approximations.
Study the decisions
Read the full walkthrough for estimates, alternatives and failure cases.