My Solution for Design Twitter (for my future reference)
by aurora_omen941
// Before you start : need a many work arounds
System requirements
Functional:
List functional requirements for the system (Ask the chat bot for hints if stuck.)...
- User should be authorised before making a tweet
- user should be able to post and share tweets
- user should see tweets from their friends/followings
- all tweets will have functionality for comment and likes
Non-Functional:
List non-functional requirements for the system...
- App should be scalable
- system should be highly available, we should prioritise availability over conssitency here to have smooth user experience
- posting and viewing the feed should be quick
Capacity estimation
Estimate the scale of the system you are going to design...
Let's make some assumptions:
- 500M DAU (5*10^8)
- Each user on average tweets twice a day. 1B tweets per day. (10^9 tweets)
- Each user on average views 100 tweets per day
Lets first think about storage capacity:
1B tweets per day and each tweet is 140 chars, considering some metadata and emoji usage, each tweet accounts for 500 bytes.
So everyday we will have 500GB of new data added. So considering a 5 year frame, it scales out to 2500GB.
2500 GB is gigantically huge data, so we prefer noSQL here.
Let's look at data model now:
Tweet:
tweet_id : primary key
created_by : user id, foreign key
created_at : date time
content : "some content by user"
medialink : "media link to attachment/pictures"
hashtags : "list of hastags"
users_mentioned : "user ids of mentioned users"
User :
user_id : primany key
created_at : date time
DOB :
nickname :
profile picture : link to profile picture
gender :
Followers : "user id of followers"
Followings : "user id of followings"
Note : We will use Blob storage for large media files like profile picture, posts images, videos or other such attachments.
API design
Define what APIs are expected from the system...
to post tweet by current user
/POST : /tweets.com/{user_id}/:
Request {
user_id : id,
content : "some tweet content"
media attachment : "some media links"
mentioned_users : user id of mentioned user
}
Response {
tweet_id : primary key
content :
created at :
attachment :
mentioned_users : user id of mentioned user
"likes": 0,
"replies": 0
}
to get updates from other profiles to create feed of given user
/GET : /tweets.com/{user_id}/feed
Authorization: Bearer
Response {
user_id : primary key
tweet_list : {
tweet_id, created_at, created_by, likes, views
}
}
to like or comment on some tweet
/POST : POST /tweets.com/{tweet_id}/comments
Authorization: Bearer
Request Body:
{
"user_id": "12345",
"content": "This is my reply!",
"media": ["https://cdn.app.com/image1.png"]
}
Response : {
"comment_id": "cmt567",
"tweet_id": "98765",
"user_id": "12345",
"content": "This is my reply!",
"created_at": "2025-09-22T10:20:00Z",
"likes": 0,
"replies": 0
}
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...
Let's look at data model now:
Tweet:
tweet_id : primary key
created_by : user id, foreign key
created_at : date time
content : "some content by user"
medialink : "media link to attachment/pictures"
hashtags : "list of hastags"
users_mentioned : "user ids of mentioned users"
User :
user_id : primany key
created_at : date time
DOB :
nickname :
profile picture : link to profile picture
gender :
Followers : "user id of followers"
Followings : "user id of followings"
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...
- There will be trade off in pull and push mechanism of tweets, and how new tweets are pulled/pushed to feed of different users.
- Database choice, tradeoff between sql and nosql
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?