Generate short URL for long URLs.
Return long URLs for redirection.
Available system
Scalable system
Estimate the scale of the system you are going to design...
POST /v1/shortURL?longURL="xyz"
GET /v1/longURL?shortURL="abc"
Relational Data to store short URL and longURL and validity time in one table
Client interact with Load Balancer.
Load balancer interacts with multiple instance of servers.
Each server will connect centralised Redis cache to store shortURL and longURL.
For generation of short URL. A request reaches to server1, then server calculates the Hash of longURL and avoids collision using any specific hashing algorithm and the shortURL and longURL key - value pair is stored in redis cache server.
For redirection when shortURL is provided and request reaches to server, then the server looks for shortURL as key in redis and corresponding longURL is fetched and redirected to based on validity of shortURL which is maintained in form ttl in redis.
Hashing algorithm can be selected based on requirement and can be customised to generate specific length of shortURL. Usually 7character hash length is enough for 300 billion urls.
Explain any trade offs you have made and why you made certain tech choices...
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?