System requirements
Functional:
List functional requirements for the system (Ask interviewer if stuck)...
Create shortened url
Update existing urls
Delete urls
Fetch original url given the shorted url
Non-Functional:
List non-functional requirements for the system...
Highly available, multiple servers in case on goes down
TTL for existing urls, 1 year TTL
Cache for LRU urls
Store all URLs in DB
Capacity estimation
Estimate the scale of the system you are going to design...
10000 new urls stored every day
100 MB for each url entry
100 MB * 10,000 entries * 365 days = 365,000,000 MB or 365 GB per year, 3,650,000 entries per year
API design
Define what APIs are expected from the system...
exposed endpoints:
/create{url} -> returns the tiny url
/delete{url} -> returns 200 on success, 400 on DNE
/update{url} -> returns 201 on success, 400 on DNE
/get{url} -> return 200 with tiny url on success, 400 on DNE
internals:
generateUrl -> generates the unique tiny url
UpdateUrl -> updates the DB with the new url
deleteUrl -> removes the url from the DB
addToCache -> adds url to the cache
removeFromCache -> remove url from cache
purgeDB -> removes urls from the DB with TTL 0
updateTTL -> updates the TTLs for urls in the DB
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...
id -> unique id generated in our system
url -> original url given by client
tiny_url -> tiny url generated by our system
ttl -> ttl for url
replication across the multiple DBs, partition the DBs so that partition 0 is handled by one DB and the next partition is handled by another DB
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...
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?