100 queries per second
Assume the length of each short url is 6 characters and 100 bytes for each URL record.
The required space would be 100 * 100 * 3600 * 24 * 10^(-6) = 864 MB in one day. And it would be 864 * 365 * 2 * 10^(-3) = 630 GB in two years.
I would use SQL because it supports transaction. There are two tables.
long_to_short table is used for returning a shortend URL while short_to_long table is used for jumping to the original address. We assume the URLs are permanent and different users would receive the same shortened URL when they input the same long URL. When we generate a short url for a long url, we must write in both tables. So we can use transaciton to manage the database to ensure the consistency.
id (pk)
long_url
short_url
id (pk)
short_url
long_url
GET /{short_url}
return a redirected Http response
POST /{long_url}
return a short url
The key point is to design a generated algorithm.
Advantage: fast
Disadvantage: it's hard to design a perfect function without any hash confliction.
Advantage: easy to implement
Disadvantage: As the number of short urls grows, there would be more and more duplications and decrease the speed
Advantage: efficient
Disadvantage: depend on the auto-increment id
Overall, Base62 should be the most suitable method because we can use id in the table as our auto-increment id.