Expose API to get a url from client
Generate unique alias for the url
Store the alias and the original url in the db.
Redirect to original url when client clicks on the alias
Do we have a retention period - expiry date of urls - say 30 years
Should be scalable and extendable
The databse should be indexed properly to fetch original urls in efficient way
Suppose the system gets 1 million tinyUrl generate requests per day
And suppose we take read write ration of 100:1, so each url is accessed 100 times on average in a day - 100 million read requests.
Number of total requests = 100 million -- rounding off
number of request per second = 5000000/(24*60*60)
=rounding up to 120 rps
suppose for each record we need 5 kb space to store
so for 1 million - about 5 TB per day
Say we store the urls for 30 years
so total storage needed = rounding to 150 TB
we need a simple mapping for shortUrl and original Url
we can use a key-value kind of mapping and store below data:
We have two microservices
We could also include a messaging system to communicate between the services, shortening Service will publish to the queue after generating tinyUrl and the Mapping Service could poll from the queue.
Also we can include a cache. For redirect requests, the service should first look into our cache.
The client sends reuqest through APIs
if it is a shortenUrl call, the request is sent to ShortenUrlService which will then apply a algo, create a unique tinyUrl and publish to queue.
This queue would be polled from a QueueService which when gets a new message, calls the Mapping Layer to persist in the db.
If it is a redirectUrl, we can directly call the Mapping Layer and return the original url, first check in cache and then in db.