Estimate the scale of the system you are going to design...
createShortenURL(originalURL string, expireDate Optional[String]) -> None
getOriginalURL(shortURL string) -> String
// Delete the shorten url of the given long url)
deleteURL(longURL string)
CREATE TABLE User (
UserId INT NOT NULL PRIMARY KEY,
UserName VARCHAR(255) NOT NULL,
UserEmail VARCHAR(255) NOT NULL,
AuthToken VARCHAR(255) NOT NULL
)
CREATETABLE URLMapping ( shortenURL VARCHAR(255) NOTNULLUNIQUE, OriginalURL VARCHAR(2048) NOTNULL, CreatedGMT DATETIME NOTNULL, ExpireGMT DATETIME );
The users request first go to the client service, which does the authentication process, we could have a rate limiter to protect our system from melicious behavior
If the request pass the auth and rate limiter check, it will go to nginx, to distribute the request to one of webservers
We could have an offline key generator service to generate the keys for shorten urls, and store the generated keys to key db, whenever the request needs new short url, we assign the generated key to it, and store them in shortlong url matching table
For getting request, the request will first go to cache, if the cache missing, then it will go to the url maching database, if the url is expired, delete the row, otherwise return the original 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...
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?