List functional requirements for the system (Ask interviewer if stuck)...
1.Given a longer URL system should return corresponding short URL
2.Given short URL system should redirect to corresponding longer URL
3.System should not have tiny URL collision.
4.Possible characters to be included in the Tiny/Short URL
List non-functional requirements for the system...
1.How many URL's expected to be stored in system.= 1 billion
2.Average URL shorting request per second.=100
3.Average URL redirect request per second.=1000
4.Latency and throughput of write request.=Latency 100ms, Throughput 100
5.Latency and throughput of redirect request. =Latency 10ms, Throughput 1000
6.Average Long URL length= 300 byte
7. Average short URL length = 15 byte
Estimate the scale of the system you are going to design...
Storage capacity short url= 1billion * 15 byte(average size) =15 gb
Storage capacity of long url= 300 * 1billion = 300 Gb
Define what APIs are expected from the system...
API 1
HTTP verb: POST
HTTP payload: {url :""}
HTTP header: userInfo:"", content-type, accept-type, access_token:""
Res:
{tinyURL:""}
API2
HTTP verb: DELETE
HTTP payload: {tinyURL :""}
HTTP header: userInfo:"", content-type, accept-type, access_token:""
Res:
API3:
HTTP verb: GET (TinyURL)
response:
redirect to 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...
Table1
USER {ID(Primary key), user_name}
URLMAPPING{ID(primary key),tiny_url, long_url,userid(Forgine key)}
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...
I need following component
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?