List functional requirements for the system (Ask the chat bot for hints if stuck.)...
List non-functional requirements for the system...
Estimate the scale of the system you are going to design...
Assume US population of 200 million. 50% are daily active users (i.e. 100M users). Each user send 1 url per day. That's 100 million url per day. Assume on average url are 100 characters (max is 2000). This is 10GB per day. Forecast this over 5 years, we have 100 million * 365 * 5 = 182 billion urls. This will be about 18 TB of data without compression.
Define what APIs are expected from the system...
There is only one API to shorten a url:
Then, when the shortened url is visited, it simply redirect to original 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...
On average, we need 6 characters in base64 to encode 182 billion urls. To give ourselves some buffer, we can use 8 characters.
The schema can be as followed:
table: long url is primary key, short url is value
index: short url is primary key, long url is index
Using a table, we can store long url and deduplicate them. Using an index, we can support redirection quickly.
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...
We would have a fleet of frontend servers that renders our web page for application. In the application, the user would be able to submit a url and receive a short url.
We would have another fleet of backend server to redirect traffic. The backend server would read data stored in a database and redirect with the long url. This can be done with a simple cloud-based database like DynamoDB.
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...
Submit flow:
Redirect flow:
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...
The backend will employ a simple random generate with 8 characters and check if the url is already in use.
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?