← Questions
Design TinyURL: a URL shortener with fast redirects
0
I was asked this
No reports yet. Sign in to say where you were asked it.
Design a URL shortener like TinyURL. It turns a long URL into a short link (for example https://s.example.com/aZ9k2Qx) and redirects visitors to the original URL. The workload is read-heavy: billions of redirects a day, far fewer new links. Users can optionally choose a custom alias and an expiry date.
Requirements
- Functional: create a short link for a long URL; optional custom alias; optional expiry; redirect a short code to its URL; optional click counts.
- Non-functional: billions of redirects a day with low latency worldwide; high availability for redirects; short codes unique and hard to guess if required; links last for years.
Clarifying questions
- How many new links per day, and what read/write ratio?
- How short must codes be, and may they be guessable (sequential)?
- Does the same long URL always get the same code, or a new one each time?
- Permanent (301) or temporary (302) redirects? (It matters for analytics.)
- Are click analytics and abuse prevention (phishing links) in scope?
What a strong answer covers
- Back-of-the-envelope numbers: links per day, codes needed over ten years, storage, redirect QPS; base62 length (7 characters give about 3.5 trillion codes).
- Code generation options with trade-offs: a counter or ID ranges handed to each server and base62-encoded (no collisions, but guessable unless scrambled), random codes with a uniqueness check, or hashing the URL with collision handling.
- Custom aliases as a uniqueness check on insert in the same keyspace.
- Data model: code to long URL, owner, created and expiry times, in a key-value store partitioned by code.
- The redirect path: CDN and in-memory cache in front of the store, with cache-aside reads; 301 versus 302.
- Expiry handled lazily on read plus background cleanup; deleted codes not reused.
- Analytics recorded asynchronously from redirect logs so the redirect stays fast; rate limiting and malicious-URL scanning on creation.
Follow-ups
- A link goes viral and gets a million hits a minute.
- Generate unique IDs across regions without a single coordinator.
- Let users edit where a short link points, safely.
- Detect links that turn malicious after they were created.
Sign in to see the worked answer
The full answer, chapter by chapter, with what interviewers expect at each level. Free with an account: one full answer per company.
What the labs asked this week
A weekly email of what OpenAI, Anthropic and the other top AI labs asked engineers, round by round.
Sign in to see the worked answer
The full answer, chapter by chapter, with what interviewers expect at each level. Free with an account: one full answer per company.
Draw your answer hereBoxes, arrows and notes, saved for you to come back to.Sign in to start drawing


