My Solution for Designing a Simple URL Shortening Service: A TinyURL Approach with Score: 8/10
by vertex9024
System requirements
Functional:
- Users should be able to map long URL into short URL
- Users should be able to fetch long URL from short URL
- URL should be persistent for a certain period of time
Non-Functional:
- Availability
- Performance
- Scalability
Capacity estimation
- Around 5000 RPS for total of roughly 200 million URLs
API design
POST /longurl returns shorturl
GET /shorturl returns longurl
Database design
- url (id, short, long, createdAt)
- analytics(id, url_id (foreign key), other analytics )
High-level design
- Scalable, large blob database for storing urls since its not easily modified, high read low write
- Back end with # replicas based on RPS performance of each replica pointed to one database
Request flows
- Client requests long url
- Backend fetches long URL based on shortURL
- returns long URL
- Client posts long url
- Backend checks if long URL in db
- if so return short URL, else create and return new short URL
Detailed component design
- Some sort of hash algorithm to make sure the shortened URL is sufficiently randomized
Trade offs/Tech choices
- Trade off database performance for scalability
- trade off write/update capabilities in database
Failure scenarios/bottlenecks
- Backend RPS performance
Future improvements
What are some future improvements you would make? How would you mitigate the failure scenario(s) you described above?