create a unique shorten url for a given long url
Redirect request with shorten url to long original url
stable response for generating new short url and quick redirecting from short url to original url
handle multiple requests at the same time
200 rps for generate short url
20000 rps for redirecting short url to long url
get(shorten_url) -> return long_url
post(long_url) -> generate short_url and store it in database
shorten url to original url map(key value: short_url original_url) for quick lookup and redirecting. Redis is a good choice. Also we can have a cache layer for quicker look up.
You should identify enough components that are needed to solve the actual problem from end to end. Also remember to draw a block diagram using the diagramming tool to augment your design. If you are unfamiliar with the tool, you can simply describe your design to the chat bot and ask it to generate a starter diagram for you to modify...
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...
1) shorten request: user input a original url in client, server process this input and generate a short url to store in the database and return the short url to client so the user can share it.
2) redirecting request: when user enter the short url, server receive the request, and then lookup in the database to get the original url, send the original url back to the client to redirect in browser. If the short url is invalid (not found in database), return a invalid input error.
Generate shorten url, we can use a hashing method to generate a unique string. And each original url should have a unique hash value so that is a unique shorten url. For duplicate input, we don't need to do it twice, we can check if the short url is already exist. so we can save some space in database. Also we can have a time limit for all the entries, for example, we only keep the shorten to original url relationships for 1 month. As in most use case, the shared url will be used in a month. In this way, we can further save space.
quick response vs reliable: for this use case we choice quick response over reliable by using noSql database.
Try to discuss as many failure scenarios/bottlenecks as possible.
Add user log in/ auth component