List functional requirements for the system (Ask the chat bot for hints if stuck.)...
List non-functional requirements for the system...
Estimate the scale of the system you are going to design...
Let's assume we have:
Based on these estimations, on average an active user issue 3 read requests per minute.
Total read requests rate = 10000 (peak users) * 3 (requests per minute per user) = 30000 read requests per minute.
Average write requests per minute - 5 * (1 (comment) + 2 (likes) + 1(reply) = 20
Assume each comment and its replies cost around 1KB. We need to store
5 (comments per minute) * 60 * 24 * 365 * 3 = 8GB data.
This data could be stored in a single database machine.
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...
Topics Table
Comments Table
Users Table
Upvotes Table
Downvotes Table
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...
The system should include the following items:
Client: The web browser or mobile app used by users to read and post comments.
Load Balancer: A load balancer to distribute the traffic across various servers in the service.
Comments Service: The main service that manages read / load comments
Comments Database: The database that stores comments-related tables.
AAA Service: A service that manages authenticating users and the users' permissions.
Users Database: A database that stores user-related tables.
Cache: A cache that stores recently loaded comments to reduce read time.
Data Retention Job: A job should be run periodically to remove comments older than 3 years.
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...
The request flow should be as follows:
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...
Cache: The cache is added to reduce the system turnaround time for reads.
Load Balancer: We chose a load balancer because we have a large-scale system and would like to distribute the traffic across various comments service servers.
Databases: Although the data could theoretically be stored in a single machine, we'd like to have a few redundancies to maintain the system's availability. Therefore, we should have duplication of the databases, ideally in the master-slave pattern. Data should be written to the master and read from the slave.
Explain any trade offs you have made and why you made certain tech choices...
The cache in this design is chosen to be read-through and write-through for following reasons.
Try to discuss as many failure scenarios/bottlenecks as possible.
Examples of failure scenarios are as follows:
What are some future improvements you would make? How would you mitigate the failure scenario(s) you described above?
In the future, more duplications and partitions should be introduced as the user scale up.