More reads than writes 10:1 (reads: writes)
1 million active users for a day
12000 Reads per second
1200 writes per second
User UI -> LoadBalancer -> Application servers (url shortner generator) connected to a database.
For reading, use Redis for caching the most-recently URLs. We can also add analytics service
user inputs a long URL, URL generator service will generates a short URL and stores in the database and redirects it using the redirecting service.
URL generator sevice: takes the original long URL. Converts it into a md5 hash whichis 32bit hex.
With the generated hex a short URL is generated and also checks for duplicates. Then checks stores it in the database. If user provided a custom alias, then this service will check if that alias is already in the database or not. If it is in the database returns a error that the URL is already in use. else it stores and maps it to the original URL
For it to be highly available we create shards for the database and horizontally scaled the databases. So Here we follow eventual consistency.
Must be able to solve the hash collisons which might occur if two long urls produce same md5 hash.
Expired URLs must be removed from the database and should not support any redirects.
What are some future improvements you would make? How would you mitigate the failure scenario(s) you described above?