Twitter System Design

aditya goel
3 min readNov 5, 2022

Welcome to this blog. We shall learn about the system design of twitter.

Question:- Let’s first look at the twitter’s basic functionality first :-

  • HomeTimeline is the one, where user sees his/her friend’s tweets.
  • UserTimeline is the one, where user sees his/her own tweets.

Question:- Now, let’s see the functional requirements :-

Question: -Nature of the twitter is not that sort of transactional type. It’s nature is like as mentioned below :-

Question:- Where do we keep the tweets, once created ?

  • User Table → Stores user information.
  • Tweet Table → Stores the tweets information.
  • Follower Table → Stores the mapping between the users.

Question:- We also store following lists in Redis :-

  • <UserId, List_of_Tweets> → To be used for User Timeline.
  • <UserId, List_of_Followers> → To be used for Home Timeline.

Question:- How does UserTimeline is computed ?

Question:- How does HomeTimeline is computed ?

Question:- How does FanOut approach works ?

  • Say User U1 have 100 friends/followers.
  • Now, when user U1 tweets, then first and foremost the pre-computed UserTimeline is updated in Redis.
  • Secondly all the 100 friend’s HomeTimeline is also updated. It means that, we store the pre-computed HomeTimeline into the Redis.
  • Whenever any one of 100 friend, opens their respective HomeTimeline, the same is fetched from the Redis and shown.

Question:- Does FanOut approach works in case of Celebrity as well ?

No, it doesn’t works.

  • A Celebrity may have Millions of followers.
  • Whenever celebrity tweets, it’s not advisable to update the HomeTimeline of all those Million followers.
  • In this case, mix & merge approach is adopted.

Question:- What does the trending items means ?

Question:- Based upon what factors, a tweet becomes the Trending Tweet ?

Question:- How does we process the trending tweets ?

Question:- How does the search functionality works with twitter ?

Question:- Whats the design of the Search database ?

It’s something similar to the ElasticSearch design, which consists of the multiple nodes n the cluster.

Question:- How does the overall system looks like ?

That’s all in this section. If you liked reading this blog, kindly do press on clap button multiple times, to indicate your appreciation. We would see you in next series.

--

--

aditya goel

Software Engineer for Big Data distributed systems