Estimate the scale of the system you are going to design...
Let's say there are 200 requests per seconds in creating new shortened urls.
And there are 20K requests per second for redirecting from shortened to actual urls.
If the shortened url has an expiration date of 1 year, then 200 * 60 * 60 * 24 * 365 = about 7B urls stored each year
Now for the shortened url, it can be made up of lower case letters, upper case letters, and numerical digits. That's 62 characters.
Lets say a shortened url will be composed of a domain name - https://tinyurl.com/{some characters} and {some characters} will be length 6. This will give us about 60B possible short urls with our 62 characters.
So a shortened url is 6 bytes. We can append the prefix instead of storing the prefix. Lets assume the real url on average would be 200 bytes. So 7B * 204/1000/1000/1000 = about 1.5 TB
POST /url/shorten
input: {
real_url: ""
expiration_date: optional
custom_short_url: optional
}
output: {
short_url: ""
original_url: ""
}
GET /
This api will return a redirect
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...
urls table
short_url
original_url
timestamp
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?