System requirements
Functional:
List functional requirements for the system (Ask the chat bot for hints if stuck.)...
- Tweet: Compose and share messages of up to 140 characters.
- Follow: Users can follow other users to see their tweets.
- Home Feed: Users can view only the tweets from the users they are following.
- Liking tweets
Non-Functional:
List non-functional requirements for the system...
- Daily Active Users (DAU): Let's assume around 500 million DAU. This is based on users' patterns observed in similar social networking platforms.
- Peak Concurrent Users: At peak times, it's reasonable to estimate that about 20% of DAU will be active simultaneously, which translates to approximately 100 million concurrent users.
- Tweets per User: On average, users might tweet about 2 times a day, resulting in about 1 billion tweets generated daily.
- Response Time: When a user accesses their home feed, the first 10 tweets should load within 500 milliseconds to ensure a good user experience.
- Scalability: The system should be able to scale horizontally to accommodate an increase in user base without sacrificing performance.
Capacity estimation
Estimate the scale of the system you are going to design...
- Daily Active Users (DAU): Let's assume around 500 million DAU. This is based on users' patterns observed in similar social networking platforms.
- Peak Concurrent Users: At peak times, it's reasonable to estimate that about 20% of DAU will be active simultaneously, which translates to approximately 100 million concurrent users.
- Tweets per User: On average, users might tweet about 2 times a day, resulting in about 1 billion tweets generated daily.
- Response Time: When a user accesses their home feed, the first 10 tweets should load within 500 milliseconds to ensure a good user experience.
API design
Define what APIs are expected from the system..
We could have following API endpoints
/publish(user_id, tweet) returns a success/fail boolean
/follow(from_user_id, target_user_id) returns a success/fail boolean
/unfollow(from_user_id, target_user_id) returns a success/fail boolean
/getTweets(user_id) returns a paginated list of tweets from people the user_id follows
/likeTweet(user_id, tweet_id) => void
/unlikeTweet(user_id, tweet_id) => void
/getFollowers(user_id) => returns a list of followers of a user
/getFollowing(user_id) => returns a list of people the user is following
/getUserProfile(user_id) => returns user information
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...
We would need the following tables and schemas:
Users table
user_id
user_name
other personal info
Tweets table
tweet_id
user_id
published_at
like_count
Likes table
author_user_id
tweet_id
like_user_id
Followings table
following_user_id
followed_user_id
last_following_date
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...
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?