System requirements


Functional:

List functional requirements for the system (Ask interviewer if stuck)...

As a user ability to pass URL and in return get a short URL.

What all characters are allowed to make it easy to remember lets use lowercase a-z and 0 -9

Multi language, for now shall we keep it english


Ability to add and delete URL provided user is authenticated and subscribed.

Free User can shorten only 5 ( or x URLs )


Non-Functional:

List non-functional requirements for the system...

System should be highly available

it should be scalable to handle multiple parallel requests

have low latency



Capacity estimation

Estimate the scale of the system you are going to design...

so, tiny URL will be something like https://mydomain.com/<>

Lets define length of last character, a-z o-9 is 36 characters and if we take 5 character ong then 36^5 should be ok to store billions of URL



API design

Define what APIs are expected from the system...

API with one input parameter which is URL and return is short URL



Database design

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...


we need to store id, userId, longURLHash, URL, shortURL, timestamp

It should be a distributed database catering accross geography

Redis


High-level 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...


Each long URL we will pass to the hash function which will return a string of 5 characters.

this has will be appended as parameter in short url like

https://mydomain.com/hash


Upon click of this short URL in return user will be redirected to orignal url i..e 301 or 302

we will avoid 301 as it has some caching so use 302


Request flows

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...






Detailed component design

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...






Trade offs/Tech choices

Explain any trade offs you have made and why you made certain tech choices...






Failure scenarios/bottlenecks

Try to discuss as many failure scenarios/bottlenecks as possible.






Future improvements

What are some future improvements you would make? How would you mitigate the failure scenario(s) you described above?