List functional requirements for the system (Ask interviewer if stuck)...
List non-functional requirements for the system...
Estimate the scale of the system you are going to design...
Define what APIs are expected from the system...
POST /api/v1/url
Headers: User jwt token/session token
Body:
* original url (limit it to 64 bytes)
Response:
* shortened url
GET /api/v1/url/:shortened-url-id
Response:
* Original url --> used to do HTTP redirect to it
DELETE /api/v1/url/:shorted-url-id
Headers: user jwt/session token
Response:
* HTTP 204 if deleted
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...
Entities:
* URL
* User (out of scope)
* user_id
* ...
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...
* Client iteracts with load balancer
* load balancer talks to multiple redundant servers
* Servers talk to DB to fetch data
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...
* Create URL
* Get URL
* Delete URL
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...
* SQL DB since reads are more frequent than writes, and it makes look ups fast
* Look aside cache so we don't cache entries that aren't accesssed
Try to discuss as many failure scenarios/bottlenecks as possible.
* Bottleneck could be DB, so we add read replicas and also can consider sharding if we need to scale the DB
* With cache, potentially user can continue to access url after it is deleted, we can make sure we delete the entry in the cache after it is deleted from the DB, more complex logic and there may be a slight delay when the url is still accessible but should be fine given we are not strongly consistent there
What are some future improvements you would make? How would you mitigate the failure scenario(s) you described above?
* Possibly geo replicate the DB so we store URLs closer to the geo graphic region where it was created, and depending on the access patterns, we can replicate it across geos