TinyURL/Bit.ly Flashcards
Requirements
Functional 1. Shorten URL 2. Redirect to original link 3. Custom alias 4. Expire links after some time. Non Functional 1. Highly available. 2. Redirection should have minimum latency 3. Not guessable links Extended 1. Analytics 2. Rest API for other services.
Back of envolope calculations
- 500M new url shortening requests per month
- 100 clicks per shortened
Traffic estimates
- 500m/month == 200 URLS per second
- 50B/month = 20000 URLS per second
Storage
lets say we store 5 years worth of URLS. Then we have 30 billion URLS
Lets say a URL takes 500 bytes, then we need 15 TB of storage.
Bandwidth
For write, we need 200 * 500 == 100KBPS
For read we need 100 * writes = 10 MBPS
For caching 20% of URLS, we would need 0.2 * 20k * 3600 * 24 == 170GB of memory
API definition
creatURL(key, original_url, custom_alias=None, user_name=None, expiry_date=None)
deleteURL(key, short_url)
Rate limiter
Data storage model
Since these are key value pairs, we should use NoSQL. Something like cassandra will scale well. In this case, we need to store userid:url in another table.
Encoding
Base36, Base62 or Base64.
Length: 68billion for Base64 with 6 chars.