Twitter is an online microblogging and social media platform where people post and interact with messages called as tweets. Registered users can post, like, and retweet tweets, but unregistered users can only read them.
Prerequisites :
System design introduction : 3 principles of distributed system, 5 step guide for System design.
System design concepts & components : Horizontal scaling, Database, Communication protocols, Caching
Functional requirements
Non-functional requirements
Additional requirements
User : userId(PK), name, email, creationDate, lastLogin
Tweet : tweetId(PK), data, location, creationDate
Follow : userId1, userId2
Which database to use?
Column-wide database like Cassandra.
Question :
If we have 1 million tweets sent each second with average tweet size 1 KB we need to calculate how much data will be generated in next 5 years?
Answer :
We can consider twitter as an extension of the reader/writer design problem.
Challenge :
Suppose a user follows 500 people out of which 200 tweet daily. What are the different ways to populate the user’s timeline.
Solution :
Challenge :
Our solution works perfectly fine for normal users. But for celebrity users we have a problem. They have millions of followers.
Solution :
Pregenerate the feed of only normal followers.
Challenge :
How to refresh the feed?
Solution :
Challenge :
How do we handle infinite scrolling and loading the older tweets.
Solution :
Let the system compute 20 additional tweets beforehand each time we load 20 tweets.
Let us see our non-functional requirements.