We need to use at least 7 characters in our URLs.
Each short URL is approximately 7 bytes
Let's assume each long URL will be a maximum of 100 characters in length, therefore it's 100 bytes of storage
The user metadata and URL clicks info is about 500 bytes in size
Therefore, we have a ceiling of 1000 bytes to store for each URL (long, short, and user and URL clicks metadata)
For 315,360,000,000 URLs * 1000 bytes = 315,360,000,000,000 bytes = 315 Terabytes
Define what APIs are expected from the system...
{
"longUrl" : "https://thisisanexample.com"
}
{
"shortUrl": "https://tiny/u47rqql"
}
Defining the system data model early on will clarify how data will flow among different components of the system. Also you could draw an ER diagram using the diagramming tool to enhance your design...
{
"shortUrlId": "r34l9aq",
"longUrlId": "https://thisisalongurl.com",
"creationDate": "2024-12-30T12:00:00Z",
"userId": "user341",
"clicks": 1023,
"metadata": {},
"isActive": true
}
Given that we estimate that 1000 URLs will be created per second, we can expect to have 1000 DB writes per second. Therefore we can estimate to have between 10000 to 100000 reads per second.
We can use a NoSQL database for this solution since we are not really looking for ACID compliance. Apache Cassandra, MongoDB, etc would be good
You should identify enough components that are needed to solve the actual problem from end to end. Also remember to draw a block diagram using the diagramming tool to augment your design. If you are unfamiliar with the tool, you can simply describe your design to the chat bot and ask it to generate a starter diagram for you to modify...
Explain how the request flows from end to end in your high level design. Also you could draw a sequence diagram using the diagramming tool to enhance your explanation...
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...
We can use the URL Shortener Service to generate all possible short URL keys (3.5 trillion URL keys) and store then in a SQL database (the keys DB) and we can mark each key as either used or not used. We need to use an ACID-compliant DB in the event that a key is assigned to two separate users.
We can have a background job service that runs once a day and purges URLs that have maxed their TTL.
We'll introduce a caching layer to cache popular URLs. We can choose either an LRU cache or a TTL cache to implement a cache eviction policy.
For our database. We can use a key-based sharding system to distribute URLs across the shards. We can also implement master-slave replicas for each shard. We can use the master for read-and-write operations and the slaves for read-only operations.
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?