Let's consider the following requirements
URLs per second: 100 * 1000000/10000 = 1000 URLs/sec (24 hr -> 86400 ~ 10K)
Write operations: 1000 URLs/sec
Read operations: 10 reads: 1 write -> 10,000 reads/sec
Storage:
This service will primarily have two APIs
301 response code means URL has been permanently moved to Long URL and browser will cache it, subsequent requests for the same URL will be redirected to Long URL by the browser itself.
302 response code means URL has been temporarily moved to Long URL and sebsequent requests will be sent to our service by browser. Since we're not tracking any analytics like click rates, we will stick to 301 response code.
Good choice for this usecase is NoSQL database. We're planning to use cassandra.
Two table will be created
We will create a hash for each long url and store the details in the first table and add another record in long_urls. Second table is for duplicate URLs check.
For hash we're choosing base62 encoding of long_url and hash length of 7 is enough to create 62^7 ~ 3 Trillion URLs.
When Client will make a request a loabalancer and it will get forwarded to one of the servers.
When client makes a request with long URL. Server will assign a key to the longurl and store it in the database. This key will be base62 encoded and return a short URL. The encoded URL will be stored in cache with some TTL asynchronously.
When client makes a request with short URL. Server will first check in cache and return long URL else it will fetch from DB, store it cache asynchronously and return the long URL.
Dig deeper into 2-3 components and explain in detail how they work. For example, how well does each component scale? Any relevant algorithm or data structure you like to use for a component? Also you could draw a diagram using the diagramming tool to enhance your design...
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?