Overview
Design a url shortening service. like bit.ly.
Use case
- Shortening: given a url -> return a much shorten url.
- Redirection: take a shorten url -> redirect to the original url.
- Custom url.
- High availability of the system.
Tasks break down
- New urls per month: 100M.
- 1 billion request per month.
- 10% from shortening and 90% from redirection
- Request per second: 400 (40: shortens; 360:redirection).
- 6 billions in 5 years.
- 500 bytes per url.
- 6 bytes per hash.
- 3TB for all urls, 36GB for all hashes (over 5 years).
- New data was written per second: 40*(500+6):20K.
- Data read per second: 360*506 bytes: 180K.
Abstract Design
- Application service layer (serves the requests)
- shortening service.
- redirection service.
- Data storage layer (keeps track the hash -> url mappings)
- Acts like a big hash table: stores new mappings and retrieves a value given a key.
hashed_url = convert_to_base62(md5(orginal_url + random_salt))[:6]
Bottlenecks
Traffic is probably not going to be very hard, data - more interesting.