List functional requirements for the system (Ask interviewer if stuck)...
List non-functional requirements for the system...
Estimate the scale of the system you are going to design...
Define what APIs are expected from the system...
A rest api should be sufficient.
GET /shortenedURL should return a 302 found, with a header that contains the target URL GET /shortenedURL/clicks for info on how many clicks the shortenedURL has generated.
POST /create should return a 201 if created and redirect the user to the new shortened 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...
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...
Server will have a load balancers in place.
Server will have a static ip address.
Server domain will resolve to a single ip address that is an anycast ip address. it means they always get the closest and fastest data center.
Server will replicate to different geo-distributed regions.
Server will serve multiple languages.
Server will accept either browser or api traffic.
Server will have two routes:
/create for creating new shortenedURLs
/shortenedURL for getting urls using shortenedURLs
Server will either return a shortenedURL for create, a URL for get requests to an existing shortenedURL, otherwise return an error page.
Database will store the URL together with a hashed ID, which is the shortenedURL. So /abc123 is the shortenedURL and hashed ID and number of clicks. It will generate numbers and uppercase or lowercase letters based on a sha-256 hash of the URL.
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...
POST a url to /create
this checks if there is already a shortenedURL for that URL
if yes, return that shortenedURL
if no, generate a new shortenedURL
check if the shortenedURL exists
if yes, generate a new shortenedURL
if no, link the shortenedURL to the posted URL and return it to the client.
GET a /shortenedURL
this checks if there is still a URL
if yes, return that URL
if no, return a 404 not found
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?