We expact to have 100 M of users. Each users stores 100 url on average. That's 100 M * 100 = 10 Billion Key-value pair. Each K-V pair needs 1k byte. The total storage we need is 100 TB.
Assume 10% of users are DAU. That's 10M DAU. Each user would use 10 time each day.
So QPS = 100M / (24 * 60 * 60) = ~10 ^ 3
With Base62 encoding, we might need log62(10 ^ 10) = 7 characters for short URL
We'll need two API for this service.
Get: tiny.url/abcdXYZ, we'll returns the original URL
POST: tiny.url with original URL in the body. We'll return shorten URL
The database will show as follows
shorten url - primary key
user id - secondary key
original url
creation time
expiration time
We'll use k-v store to store data to achieve high throughput and availability. We can use DynamoDB or Cassandra and set it to high consistency to meet our performacne requirement
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. If you are unfamiliar with the tool, you can simply describe your design to the chat bot and ask it to generate a starter diagram for you to modify...
We have a API gateway to prevent DDOS attack. The API gateway also served as load-balancer to distribute traffic evenly to each server. It also functions as a router to route request to either shortening services or mapping services
The Shortening services will process POST request(i.e. add new shorten URL). It's stateless since it doesn't need context to create short URL and write to 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?