Throughput:
Storage Estimation:
total storage = 127 bytes
total url per year = 127 * 1000000 * 365 = 127,000,000 = 46 GB
Bandwidth:
Assuming HTTPs 301 request is about 500 bytes(including headers and all)
Caching estimation:
we will use REST API.
Endpoint: POST /shorten
This endpoint creates a new short URL for a given long URL.
sample request:
{
"original_url" : "....",
"custom_name" : "" //optional
"expiration_date" : "....", //optional
"user_id" : "...."
}
sample response:
{
"short_url" : "...",
"original_url" : "...",
"expiation_date" : "...",
"creation_date" : "..."
}
Endpoint: GET /{short_url_key}
This endpoint redirects the user to the original long URL.
Sample Response:
HTTP/1.1 301 Moved Permanently Location: https://www.example.com/some/very/long/url
A NoSQL database like DynamoDB or Cassandra is a better option due to their ability to efficiently handle billions of simple key-value lookups and provide high scalability and availability.
We would need two tables: one for storing url mappings and one for storing user related information.
url_mapping_table features : {url_id , user_id ,short_url ,long_url ,creation_date ,expiration_date ,click_count}
user_table : {user_id ,name ,password ,e_mail}
Load Balancer: Distributes incoming requests across multiple application servers.
Application Servers: Handles incoming requests for shortening URLs and redirecting users.
URL Generation Service: Generates short URLs, handles custom aliases, and manages link expirations.
Redirection Service: Redirects the users to the original URL.
Database: Stores mappings between short URLs and long URLs.
Cache: Stores frequently accessed URL mappings for faster retrieval.
Analytics Service (optional): Tracks usage statistics like the number of clicks, geographic location, etc.
Shortening URL Flow:
User sends a request to Load Balancer to shorten a URL.
Load Balancer forwards the request to an Application Server.
Application Server interacts with the URL Generation Service to generate a short URL.
URL Generation Service stores the mapping in the Database and returns the short URL.
Application Server sends the short URL back to the User via the Load Balancer.
Redirection flow:
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?