System requirements
Functional:
- User should be able to create account with unique username
- User should be able to edit their profile settings or delete profile
- User should be able to make posts under 140 characters
- User can delete their post
- User can interact with a post or comment by liking, commenting, retweeting and reporting
- User can interact with another user by following or blocking them
- User can search for another user or content; AI will be used to rank and display the most relevant content
- AI can auto recommend contents that the user is interested in
- User will be notified when another user interacts with their post or following them
- System should respect account privacy settings
Non-Functional:
- System should handle large volume of both read and write, especially in busy hours like holiday season
- Minimal latency when posting contents
- System should detect scripted or fraudulent behavior and block them
- Effective management of inappropriate content
- Effective recommendation from AI systems
- Detailed logging and metrics collection
Capacity estimation
Assume there are 5B total accounts and 1B monthly active users
Each active user makes on average 4 posts every month, and browses 10 posts daily. That's 200M daily posts and 10B daily post reads. Expect both reads and writes to be more than double during peak hours.
System needs to handle 100M users online at the same time
API design
Define what APIs are expected from the system...
POST /api/tweets
POST /api/tweets/comments
POST /api/tweets/likes
GET /api/tweets/{id}
GET /api/tweets/comments/{id}
POST /user
GET /user/{id}
Database design
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...
High-level design
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...
flowchart TD
B["load balancer"];
n0["account registration system"];
n1["login system"];
n2["post"];
n3[("user table")];
n4["authentication"];
n5[("post database")];
n6["comment"];
n7["content filtering"];
n9["rate limiting"];
n10["user"];
n11["content view"];
n12["recommendation system"];
n13["content filtering"];
B -->|"register"| n0;
B --> n1;
B --> n2;
n0 -->|"write"| n3;
n1 --> n4;
n4 --> n1;
B --> n6;
n2 --> n7;
n6 --> n7;
n7 -->|"write"| n5;
n4 -->|"read"| n3;
n10 --> n9;
n9 --> B;
n10 --> n11;
n11 --> n12;
n12 -->|"read"| n5;
n12 --> n13;
n13 --> n12;
Request flows
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...
Detailed component design
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...
Trade offs/Tech choices
Explain any trade offs you have made and why you made certain tech choices...
Failure scenarios/bottlenecks
Try to discuss as many failure scenarios/bottlenecks as possible.
Future improvements
What are some future improvements you would make? How would you mitigate the failure scenario(s) you described above?