Assume:
10 millions write requests per day
50 millions read requests per day
write qps = 10 * 1e6 / 24 / 60 / 60 = 10 * 1e6 / 1e5 = 100 qps
read qps = 500 qps
Data size:
Assume the average length of a long url is 30 characters (30 bytes)
And short url: 6 characters
Total = 10 * 1e6 * 36 bytes/day = 300 millions bytes = 360 mb per day
1 year = 365 days = 365 * 360 = 130 GB/year
POST /api/url/{long_url}
response:
status_code = 200
{
long_url,
shourt_url,
create_at
}
GET /api/url/{short_url}
response:
status_code = 302
{
short_url,
long_url,
request_at
}
Table:
long_to_short:
{
long_url: text
short_url: varchar
}
short_to_long:
{
short_url: varchar
long_url: text
}
url component:
For database, here I choose NoSQL for the ease of future scaling. The trade off here is the time to generate the new short url, if the db grow larger and larger, it might take more time to generate a new url (since it has to check there is no duplication).
Another choice we could do is using relational database, and utilize the primary key with hashing function for the short url generation
The bottlenecks will be the short url generation while the system grow larger and larger to avoid duplicate url generation