List functional requirements for the system (Ask the chat bot for hints if stuck.)...
Should give shortened url for the given url
Given a list of complete urls, it should return list of short urls
Short url length shoud nt be more than 15 characters
Should give same output for the same input if tried several times
List non-functional requirements for the system...
Scalable - should accomodate increasing user base eg: 1 lakh to 1 million users
Consistency - shoudl return same results for same input
Reliable - should be reliable since the redirection should happen correctly
Low latency - Should give response within 2 seconds
Availablility - Should have high availability(99%)
Estimate the scale of the system you are going to design...
assume 1 billion users
500 million daily active users
so lets say an user tries 5 urls a days
so totally 500*5 = 2500 million requests per day
2500*1000000/86400 = ~30000 requests/second
64 cores server could handle = 64000 requests per second
so 1 server is good for this requirement
storage requirement:
1 long url take 30 characters and the short url takes 10 characters , so for a single url its 40bytes
let assume we get 10 request per user, so 500*1000000 * 400bytes = 200000MB ~ 200GB per day
per year it would be 365 * 200 = 73000GB~73PB
bandwidth requireent:
no much incoming or outgoing data so less bandwidth requirement
Define what APIs are expected from the system...
url/shorten - to shorten url
url/redirect - to redirect to the url
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...
we could use dynamo db to store the map of short to long url with additional properties, but the problem is we have limited query capability
we could use mongo db also
Data model:
Short url
Long url
Expiration time for purging data to save resource
created time
userid
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...
High level components are:
Application service exposing APIs
Database that saves the short, long urls, userid and other datas
Cache layer thats gonna cache the map of the short and long urls - we could use cache aside strategy, which mean it will first check in cache and then get the data from the database and then write it to the cache for quick access if the same long url requested again
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...
we could use key value store db like dynamo db
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?