High availability
Low latency
Assume:
200 requests per second for creating short urls
20, 000 requests per second for viewing short urls (redirecting short URL to long URLs)
Store 1 year data
Storage to save 1 year's data:
1 year: 200 * 60 * 60 * 24 * 365 ~ 6 Billion urls to generate. Assume the short url only contains A-Za-z0-9. So a string with 6 chars should be sufficient as 6^65 > 65 Millions. Assume the long url length is 100 Bytes on average. So the total disk space for 1 year's data is (100 + 6) * 6 Billion ~ 636GB. So at the disk level, capacity/scaling is not a concern.
Cache
Assume average lifetime of a shorten url is 30 days.
So total number of alive urls ~ 200 * 10^5 * 30 = 600 million. The total size is about 50GB. Easy to fit into the redis on a normal machine
api to create a shorten url:
POST: https://tinyurl.com/api/create
Return: a generated shorten url
api to redirect to normal url from shorten url
GET: https://tinyurl.com/{short_url}
Return: redirect to the normal url
a normal SQL database. A table called shortURL with the following columns:
shortenurl: shorten url with 6 character long
normalUrl: normal url
createdTimestamp: time
has a loadbalancer to distribute the traffic
stateless API service could scale out easily
cache helps to improve the response time and reduce the workload overhead from database
Explain how the request flows from end to end in your high level design. Also you could draw a sequence diagram using the diagramming tool to enhance your explanation...
Dig deeper into 2-3 components and explain in detail how they work. For example, how well does each component scale? Any relevant algorithm or data structure you like to use for a component? Also you could draw a diagram using the diagramming tool to enhance your design...
Explain any trade offs you have made and why you made certain tech choices...
Try to discuss as many failure scenarios/bottlenecks as possible.
What are some future improvements you would make? How would you mitigate the failure scenario(s) you described above?