SD-1 · System design
Design a URL Shortener
Asked at Mid level45 minutes
Our answers stay hidden until you reveal them.
Question
Our solution
Design a service that turns a long web address into a short link, such as sho.rt/x7Kp2Qa. Anyone who opens the short link is sent to the original page. Owners can see how many times their links were clicked.
The service gets 100 million new links a month, and each link is opened about 100 times. That makes it extremely read-heavy: about 4,000 redirects a second on average, 40,000 at peak, and a design target of 400,000. Many servers must create keys that never collide, every redirect must stay under 50 ms, and a single viral link can send a flood of clicks at one key.
Good questions to ask first
Decide what you would assume for each before you look at ours.
- 1Can users pick a custom alias?
- 2Do links expire, and can they be deleted?
- 3Do we need click analytics?
- 4How many new links, and how many clicks?
- 5How short must the link be?
- 6Do users need accounts?
- 7Does the same long URL always get the same short link?
- 8Can a link’s target change later?
How to spend the 45 minutes
- 5minPart 1: Requirements and scope
- 5minPart 2: Estimates
- 5minPart 3: API
- 15minPart 4: Architecture, stage by stage
- 15minPart 5: Deep dives and trade-offs
Sketch your own design: boxes, arrows and the numbers that matter. Then compare it with ours.Break it in the labVisual walkthrough