Shorten the URL
Redirect the user to the original url
Analytics- Storing the hit count, referrer and logging Geo location
Expiration- Allowing user to set expiry of URL
User acct
API Access- an API for programming access to shorten URL and retrieve statistics
Bulk Shortening- shorten multiple URL at once
Error handling- Should handle error and report errors as input validation and custom aliases
Whitelist/Blacklist- allow users to manage which urls can be shortened or redirected based on rules.
List non-functional requirements for the system...
performance
scalability
availability
reliability
security
maintainability
usability
capacity
compliance
for 1000 requests per second
we might need
POST /v1/createUser :-
API for new user to sign up.
Request
Header :- Content type
Body:- userName, DOB, emailAddress
Response
Header:-Content type
Body:- Response code, User ID, Status, Sub Status
This API will allow unique combination of username, DOB and email address and add the user details in backend DB. In case of invalid details being passed, corresponding error code will be sent.
POST SetUserProfile API- API to set the user profile and manage settings like URL expiry, whitelist, blacklist and predefined rules using regular expressions. Below will be the
POST genShortenedURL API- this API will shorten the provided input URL and share the shortened URL . Users can also send multiple URL's as an array and in response there will be a response array returned containing the original URL and shortened URL along with a unique URL ID for each.
The generated shortened URL's
getURLStatistics API- This API will retrieve the URL hit count geolocation etc. and share the share the URL statistics.
There can be below Tables:-
User Table- Contains the user details along with a unique user ID as primary key. To have a unique user, we can also think of using other columns like user DOB, email and phone no as a UNIQUE key combination
UserProfile Table- Will have the User ID and the preferences saved in this table.
Client- Client creating the request for Generating short URL or looking for Redirection
CDN- Client will send request to CDN URL. CDN will help in implementing the web security against known attacks. It will also have cached data available. if inquired data is not found in cache then CDN will pass the request to API Gateway to retrieve the data from further downstream DB using service.
The data retrieved from service will be stored in CDN Cache with a TTL.
CDN will also store and update the URL hit count, referred ID etc. and it will pass all this information to the Dynamo DB before the Data is removed from CDN Cache. This will be done using Edge workers on CDN.
API gateway- will read the request headers and route the request to respective API service.
Service- primarily two services - Generating the URL and retrieving the URL for redirection. URL Generation service will check for existing entries before generating the URL and generate short URL , store in Dynamo DB with a TTL, as well as Push it to Redis Cache for temporary period.
it will also implement further API security features- like OAuth, Rate limiting etc.
The URL retrieval service , will inquire the Redis cache first. if URL Data is found, it will return the response to API gateway, otherwise it will inquire the information from dynamo DB, store it in redis cache and return to API gateway.
In case if the retrieved URL is invalid or giving 404 error then, this servie will remove the particular record from Dynamo DB.
Redis Cache- It will be used to store the URL mapping for a faster retrieval with least recently used eviction policy. for the data not found in cache, it wil be stored from Dynamo DB with a valid TTL. THis will be a multi-node cluster with replication for high availability. Consistent Hashing will be used to ensure read requests are distributed uniformly across the nodes to avoid hot node problem.
Dynamo DB- it will be used as key value store, with short URL as key and long URL as value.
There has to be a house keeping job to remove the expired URL entries from Dynamo DB.
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?