Given long url -> return shortened url
Given shortened url -> redirect to original long url
High availability: The url shortener service could run properly even some exception happens.
High scalability: The system should be highly scalable to be able to handle high volume of data
High performant: The system should perform high throughput and low latency
1. Traffic volume
Total requests : 100 million * 10 = 1 billion requests per day
2. How long is the shortened url?
As short as possible
3. What characters are allowed in the shortened url?
A-Z a-z 0-9
4.Write operation per second: 1 billion / 24 /3600 =~ 11600
5. Read operation:
Total storage for 10 years is 100 bytes * 3.65 trillion is 365 PB
Post:
/api/v1/data/shorten
request payload:
{longUrl: long url string}
return: shorten url
Get:
/api/v1/shortUrl
return: long url
Apprently, this is a read heavy system, so the relational database is the better option. However, due to this high volume of request per second, we can scale the database horizontally by replicating our database using leader-follower mechanism. For example, we can have one leader replica primarily deal with write operations, and all read operations should be sent to follower replica to get better performance as we have multiple followers.
Design:
Id: 123
shortUrl: tinyUrl
longUrl: xxxx/xxxx/xxxx

Short url generation flow:
Short url redirect flow:
We can use bloom filter to check whether url is not exist in the database to further reduce the pressure of the database
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...
Service design:
Hash + collision resolution
Cache design:
we can use hash structure of Redis to store it, key is shorten url, value is long url
In approach of Hash and collision that we were selected to make the shorten url unique, we will send the long url + pre defined string request back to the application and repeat the whole process, it will leads to the high volume of request and may overwhelming our application if request traffic is very high
Other approachs dont have to repeat the whole process, but there are some other complexities also, so there are some trade offs and we should utilize them based on our needs.
What are some future improvements you would make? How would you mitigate the failure scenario(s) you described above?