URL Shortener System Design
WIP
What is a URL Shortener?
A URL shortener is a simple service, which provides the user a shorter URL in exchange for a long URL. Clicking on either URL—the original long one or the shortened one—ultimately leads the user to the very same webpage. e.g., https://tinyurl.com/ypu6s32v is a shortened URL. (Try clicking it and see where it goes!)
A few popular URL shortening services:
Why is a URL Shortener needed?
Traditionally, URL shorteners were mostly used to save space in places where text input had character limitations, such as tweets on Twitter (X). Also, sharing a shorter URL with others is easier, looks neat, and is error-free. Moreover, nowadays, a few URL shortening services have advanced features, like incorporating advertisements, tracking click counts, and letting the shortened URL be used for earning commissions.
Designing the URL Shortener
- Get some idea on the scale of the system
- How many users will use the system daily?
- How many links will be created daily (writes) vs. visited (reads)?
- Storage requirements over time (e.g., 5 to 10 years)?
- How to map the Long URL to the shortened URL?
- How will the shortened URL be generated?
- How will the Long-Short URL pair be stored in the database (SQL vs NoSQL)?
- Any time promise regarding the shortened URL? (TTL / Expiration policy, e.g., 5-year, 10-year)
- How to find if a long URL has already been shortened?
- API Design and URL redirection strategy (301 vs 302/307 redirects)
- Other Considerations
- Caching
- Rate Limiting
- Analytics (Click Counts)
- Custom / Vanity URLs
- Database Scaling (Replication, Partitioning / Sharding)