Assuming we have around 100K shortened urls created daily, we will need to maintain around 100K records and depending on their life which can be 30 days. We need to have 1M entries present in our database. Saving 2KB of data per entry means 6Gb data storage will be required. To make it work for a longer time we can keep it with 16gb disc space
We just need to store a key value pair in the database. We can use any nosql database like mongodb, aerospike, etc. I would like to create a collection with the name shortened url mapping key would be shortened url and value would be actual url. while saving, I'll also set the ttl
It will automatically handle partitioning and sharding
I need an api gateway for my system. I need load balancer for my system. I need a urlShortening service. The url shortening service will have a single data base. Authorization of api calls will be done at api gateway
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?