Design fundamentals · 1 / 4
Design a URL shortener
Your challenge
Design a service that creates short links and redirects visitors. Begin with requirements, then explain the storage and scaling decisions.
Try it first. Write down your assumptions and explain your reasoning.
1.Clarify the product and estimates
Ask about custom aliases, expiration, abuse reporting and expected traffic. For a practice assumption of 10 million redirects a day, average traffic is about 116 requests/second; a ten-times peak is about 1,160. State these as interview assumptions, not facts about a real company.
2.Start with one reliable data model
Store alias as a unique key, destination, owner and expiry. Generate random aliases with collision retries protected by a unique constraint, or encode a generated id if exposing sequential identifiers is acceptable. Validate URL schemes and protect internal-network destinations if the service later fetches previews.
3.Scale reads and manage stale state
Add cache-aside lookup when measurements justify it. Enforce expiration on reads even if cleanup runs later. Choose redirect status based on mutability and browser caching: permanent redirects are harder to change. Rate-limit creation and handle malware reports. Explain the effect of stale cache entries after a destination change.
Take it one step further
- 1.What if a custom alias is requested twice?
- 2.How do you prevent stale redirects after disabling an abusive link?
Self-review
Can you explain each point without looking at the solution?
- Explicit assumptions and units
- Unique-key collision handling
- Expiry, caching and abuse controls
