List functional requirements for the system (Ask the chat bot for hints if stuck.)...
List non-functional requirements for the system...
High Availability
Scalability
Fault Tolerance
Estimate the scale of the system you are going to design...
Define what APIs are expected from the system...
URL shortening:
POST: api/v1/data/shorten
request param: {longUrl: longURLstring}
return shortUrl
URL redirecting:
GET: api/v1/shortUrl -> return long 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. 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...
URL redirecting- client sends short URL and tinyUrl sends status code : 301 and location:longUrl and visit long URL by sending to amazon server, where it gets cached.
URL shortening - it passes through hash function and return hash value
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...
URL shortening flow -
URL Redirecting 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...
Deep Dive:
Url shortening - there are hash functions - MD5, CRC32 which can generate hash code. The hash length can be not more than 7 as there are total 62 possible characters in shorten url and 62^7 ~3.5 billion which is within our storage capacity. But this hash function can cause collision and we can take 7 characters from hash code and append predefined length +hash code(7 characters) in case of collision. It is expensive to query database if url exist, so to improve performance we can use bloom filters, which is space efficient probabilistic technique to test if an element is member of set.
Another approach - base 62 conversion which is 0-0,1-1...11-a...35-z, 36-A,61-Z since there are 62 characters we use base 62 conversion to generate hash value.
URL Redirecting Service:
As there are more read than write,
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?
Database scaling
Web server scaling
Analytics to track clicks for URL shortening