1 million writes per month * 10kb per write=10 gb per month
120gb per year
GET /api/short-url/exists
long_url
{
"short_url": "https://short.url/abc123" (or empty string if not found)
}
POST /api/url/verify-safety
{
"long_url": "https://www.example.com",
"user_id": "123"
}
{
"message": "URL is safe" (or error message if URL is unsafe)
}
POST /api/short-url/create
{
"user_id": "123",
"long_url": "https://www.example.com"
}
{
"short_url": "https://short.url/abc123"
}
GET /api/long-url/{short_url}
{
"long_url": "https://www.example.com"
}
GET /api/short-url/exists?long_url=https://www.example.com
POST /api/url/verify-safety
Request Body:
{
"long_url": "https://www.example.com",
"user_id": "123"
}
POST /api/short-url/create
Request Body:
{
"user_id": "123",
"long_url": "https://www.example.com"
}
GET /api/long-url/abc123
| Column Name | Data Type | Description | |---------------|-----------|---------------------------------| | user_id | STRING | Primary key for the user | | long_url | STRING | Original long URL | | short_url | STRING | Shortened URL | | created_at | STRING | Timestamp of short URL creation | | read_count | STRING | Number of times URL was read | | region | STRING | Region associated with the URL |
We will use sharding based on the original URL and a single leader replication to provide fast read throughput
client goes to rate limiter first, the rate limiter will have a maximim requests it can handle, it will put the excess in a message que to be processed later, if message que is full we will deny until que is empty. If rate limiter allows the connection it will go to our api. if the request is a get short we will get the short first seeing if it is in a cache (will use write around cache, with LRU eviction policy) if its not in cache it will read from our db which has sharding and single leader replication. if its a write we will first verify if the short exsists and create another write but with a different user name and time stamp, if it does not we will use verify api safety and if its safe we add it else add it to block list
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?