List non-functional requirements for the system...
Estimate the scale of the system you are going to design...
Storage requirement
Number of create requests per sec= 200
Number of create requests per year = 200 * 60 * 60 * 24 * 365 = 17,280,000 ~ 6205 million
Assuming 10% growth every year, at end of 5 years, number of requests ~ 9082 million which is ~9 Billion
We consider, each request creates a MD5 hash of URL (taking first 7 characters) to represent the short url which will be 7 bytes and also record the long url (average size ~300 Bytes) and the ttl (timetolive in epoch time) ~7 bytes in database.
So we will need a database size of 314 * 9 * 1000000000 Bytes = 2826 GB ~3 TB. Consider we create multiple replicas for durability and availability, lets approximate data size ~10TB.
Throughput Requirement
Also, assuming 200 create requests per second rising by 10% each year leading to ~300 TPS by end of 5 years
For read requests 20,000 TPS
~20k TPS overall
This is not a huge number but will require multiple Application Servers to be hosted
Bandwidth Requirement
For 20k TPS where each request returns ~300 Bytes, bandwidth required = 20 * 1000 * 300 * 8 /1000 Kbps = 48000 Kbps
Considering each 64 Kbit regular server supports 64 KBit instructions/sec processing, number of servers required = 48000/64 ~800 servers
Upper limit of servers to support burst traffic, suppose we encounter that all DAU (845,865 users by end of 5 years) request a read at the same time, number of servers required = 845,865* 300 * 8/(64000 * 8) ~ 4000 servers
Define what APIs are expected from the system...
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...
The loadbalancer provides a way to effectively distribute requests to the
We use a key-value store eg. dynamo db as a database to store our shortUrl as the key and the value is the long url string. We create database shards using consistent hashing technique. The keys (shortUrls) that are hashed by the same function fall under a specific partition and is recorded by the cluster manager.
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...
A user sends any request via client.
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?