Low level Design for Twitter
2 min readJun 6, 2021
One of commonly asked interview question is how to design Twitter. Lots of resources are available but are mostly related to High level design. Below a very basic design approach to tackle this problem statement.
System Requirements
We will focus one very basic set of requirements while designing Twitter:
- A guest user should be able to view any tweet.
- Registered user should be able to view as well as post a tweet.
- Registered user should be able to follow other users.
- Registered user should be able to comment on any tweet.
- Registered user should be able to view tweets of the people he|she follows in his Wall.
- Registered user should be able to view his own posted tweets, features like sort tweets based on Oldest|Newest should be provided on his Timeline.
- Tweets on the Wall should be sorted in a customised way. Priorities are as [Celebrity Tweet > Unseen tweet > Time of tweet]
Use case diagram
Main actors for this design are :
- Guest user : Have only access to view any tweet.
- Registered user : Can view and post tweets. Can follow and unfollow other users. View his wall and timeline.
- System : Should provide services for creating new tweets and fetching other necessary details.
Common use cases which we are going to focus is :
- Follow / Unfollow other user.
- View / post tweets.
- Creating a new tweet.
- View user timeline / sort timeline based on time.
- View user wall feeds/ Customised sorting for wall feeds.
Class Diagram
Activity Diagram
- Post a tweet.
2. Comment on a tweet.
Code
Following is the code solution :
Enums and Constants
Interfaces
Core classes and models
Source code for this design is available at