Design a URL shortener (like Bitly)
You take a long web address and give back a short one, like sho.rt/k3T9xQa, that leads to it. It's speed dial for the web: press one button and the phone dials a long number it has stored. Our service is the phone; every click is a lookup.
It's one of the most asked design questions, also asked as "design TinyURL" (the pastebin has the same shape). It touches unique IDs, a read path that must stay fast for years, HTTP details most candidates skip, and abuse.
Below is a full mock interview following the seven steps of the framework. You're the candidate: at each Guess before you read on, stop and answer first.
Step 1 · Clarify the features and cut the scope
Minutes 0–5 · How this step works
Interviewer: Design a URL shortener, like Bitly.
You: A few questions first. The core is creating a short link and redirecting anyone who opens it. Can people pick their own alias, like /summer-sale? Do links expire?
Interviewer: Custom aliases, yes. The creator can set an expiry date.
You: Do creators see click counts? Can a link's destination change later?
Interviewer: Clicks per link by day and country, no live dashboards. Destinations never change, but we must be able to disable a link, say if it points to malware.
You: Who creates links?
Interviewer: Logged-in users with API keys. Anyone can open a link.
You: Then I'll cover create with optional alias and expiry, redirect, disable, and daily click counts. Out: editing destinations, account management, QR codes and billing. OK?
Interviewer: Good.
Each answer shapes the design: aliases need a uniqueness check, expiry a "gone" answer, disabling a way to purge caches, fixed destinations long caching.
Step 2 · Non-functional requirements
Minutes 5–8 · How this step works
You: Say 100 million new links a month, opened 100 times more often than created. Redirects under 50 ms at our servers for 99% of requests, and 99.99% available (about 4.3 minutes down a month); creating 99.9%. A link is never lost once returned, and codes aren't guessable.
Interviewer: Why does creating get a lower target?
You: A failed create hits one person, who tries again. A failed redirect breaks a link on a poster or in a million inboxes, and there are 100 redirects per create.