List functional requirements for the system (Ask the chat bot for hints if stuck.)...
Input: long URL
Output: A shortened URL that redirects to . In order to keep popular URLs from overwhelming the system, a given input URL will always return the same output URL.
Stretch goal: Potentially identify variables in an input URL and add them to the end of the shortened URL. e.g. xyzwithlonname.com/lotsofurl/search?q=?q=
List non-functional requirements for the system...
Availability - we want this service to be available (e.g. return responses within 1 second) 99.9% of the time.
Performance - See above. We want the case of batched or automated requests to the system to be performant so a goal of 99% of requests in <=.1s and 99.9% of requests in <= 1s would be ideal. For a small task like checking the existence of a hash and shortening it, this should be feasible, although I am unfamiliar with networking and am not sure what bottlenecks exist there.
Scalability - estimate 10 requests per second, with a maximum batch size of 100 requests and an estimated maximum of 1,000 requests in a second.
Security - No PII in input URLs, presumably, but maybe LLM can check for that. Possible to safeguard against malicious URLS, although I'm not familiar enough with networking measures to achieve that.
Estimate the scale of the system you are going to design...
See scalability above: estimate 10 requests per second, with a maximum batch size of 100 requests per user per second and an estimated maximum of 1,000 requests in a second.
Define what APIs are expected from the system...
POST shortenURL(long_url, expiration_time=None, custom_short_url=None)
GET redirectURL(short_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...
Requirements:
URLMapping {
VARCHAR shortURL PRIMARY KEY
VARCHAR longURL UNIQUE INDEX
timestamp createdAt
timestamp expiresAt
}
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...
FE API: exposes shortenURL and redirectURL methods via API.
Server: takes requests, looks up values in the database, and creates new shortURLS as necessary
Cache: LFU cache (e.g. Redis) stores most frequently used keys.
Database: stores shortURL and longURL table, shortURL is primary-indexed for efficient lookup.
TODO: How do I pick which database to use?
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...
Client makes a request.
shortenURL(longURL):
redirectURL(shortURL)
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?