Assume we host the service for 10 years, each long/short urls take 100 bytes.
The storage is: 10000000 * 365 * 100 bytes * 10 = 3.65 TB
The avg QPS is 10000000 / 24/3600 = 115
Peak QPS is 115 * 2 = 230
Url Table
GenerateShortUrl flow:
FetchLongUrl flow:
In ShortUrlGeneratorService, we could use MDB, SHA-1 algorithm to generate a has value and use Base64 conversion to shorten the url.
For hot urls, we could add a cache in UrlDBAccessService. Then it doesn't have to query the db everytime when there is a new request.
Explain any trade offs you have made and why you made certain tech choices...
When the API server, services or database are down, it caused a single point failure issue.
For server, we could start multiple distributed servers to handle the request.
For database, we could use replication to backup the data.
If the request spikes or abuse behavior, we could add a rate limiter to filter out request based on IP address or other filter rules.