For simplicity, we'll focus on just creation of a short URL and retrieval of the original URL.
Create Short URL:
Endpoint: POST /short_url
Request structure:
```json
{
"url": "string"
}
```
Response structure:
```json
{
"shortUrl": "string
}
```
Get URL:
Endpoint: GET /url?short_url_id={string}
Response structure
```json
{
"url": "string"
}
```
This endpoint will return a 404 if the provided short URL doesn't exist.
Given the traffic estimates of 50 writes per second and 500 reads per second, it doesn't matter much what time of database is used for this system. However, I'm more familiar with relational databases, so I would use something like PostgreSQL or MySQL.
The database schema just requires a column for the short URL key (AKA ID) and another column for the original URL.
In this design, the client first hits an API gateway that will route the request to the appropriate service. The API gateway can have functionality such as rate limiting, DDOS protection, and authentication / authorization to protect the system from undesired traffic and to enforce restrictions as needed. For simplicity, I won't delve into the configuration of the API gateway.
Once the request passes the checks of the API gateway, it is forwarded to a service instance.
For requests to create a URL, the service will generate a hash of the original URL and use it as the key / ID of the short URL and then persist the entry (shortURL and original URL) in the database.
For read requests, the service will first check the cache for the given short URL. If the URL is in the cache, then it'll be returned. Otherwise, the service will fetch it from 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...
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?