Low level Design for Twitter

Shivansh Dubey
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:

  1. A guest user should be able to view any tweet.
  2. Registered user should be able to view as well as post a tweet.
  3. Registered user should be able to follow other users.
  4. Registered user should be able to comment on any tweet.
  5. Registered user should be able to view tweets of the people he|she follows in his Wall.
  6. 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.
  7. 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 :

  1. Guest user : Have only access to view any tweet.
  2. Registered user : Can view and post tweets. Can follow and unfollow other users. View his wall and timeline.
  3. System : Should provide services for creating new tweets and fetching other necessary details.

Common use cases which we are going to focus is :

  1. Follow / Unfollow other user.
  2. View / post tweets.
  3. Creating a new tweet.
  4. View user timeline / sort timeline based on time.
  5. View user wall feeds/ Customised sorting for wall feeds.

Class Diagram

Activity Diagram

  1. Post a tweet.

2. Comment on a tweet.

Code

Following is the code solution :

Enums and Constants

Interfaces

Core classes and models

--

--