create a short url by given original url
redirect short url
query by original url
query all urls
analytics
custom short urls
urls storage will grow double in a few years, need a high scalable system to handle the growth, Need a high consistence database, can give up some availability since we don't require it response every time we request.
Can tolerant 1 million users, average QPS would be 58, the peak QPS would be 3 times of average around 174
void create_short_url(String url)
/***
create a shorted url by using provided url, first to use a if condition check whether given url is a valid url, then we will use a hash function to generate a shorted url, finally validate with Database to ensure this is a unique url, and write in Database
API Method: PUT https://www.shorternURL/create_short_url/{url}
***/
String query_shorted_url(String url)
/***
GET method to get the shorted url in database by using given original url, check its a valid given url, then try query in DB search by the given URL, error handling if shorted url not exist
API Method: GET https://www.shorternURL/query_shotred_url/{url}
***/
String redirect_url(String shorted_url)
/***
GET the original URL in database by given shorted_url, error handling if original url doesn't exist or original url return not 200 status code.
GET https://www.shorternURL/redirect_url/{shorted_url}
***/
Map
/***
GET list of all urls and return in a map data structure.
GET https://www.shorternURL/query_all_urls
***/
String custom_short_urls(String url)
/***
let user self-define the shorted url, need a validation function to ensure it's not an existing shorted url
***/
/***
I gave some explanation of each API method instead of implement them in here. There are other functions Need to be added such as boolean validate_url(String url) to check whether this url return 200 and not duplicated in DB, and a hash function to shorted URL, I may consider to use Base62, or CRC32. I won't consider to add rate limiter in here since we only have 58 in average QPS.
***/
Defining the system data model early on will clarify how data will flow among different components of the system. Also you could draw an ER diagram using the diagramming tool to enhance your design...
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?