I'm trying to design a system similar to Twitter's timeline, but I can't wrap my head around how to get updates from so many followers while remaining efficient. Let's say I'm following 1000 people on Twitter. When I go to my feed, how does it know which tweets to show me? This is what I'm thinking, but it seems extremely inefficient and unlikely:
You have 10,000 friends.
In a for loop, loop through each friend, getting their latest
status updates since their last update.
But that just seems ridiculous to loop through 10,000 friends. I can't imagine how else they'd do it though. Or would it be something like:
Someone I am following posted a tweet. That tweet is inserted in
an array containing the tweets of all people I am following.
But then that would seem weird, if I followed someone new who has 20,000 tweets, then 20,000 tweets would be inserted in my array, and if that person has millions of followers, then there are a million X 20,000 copies of the same set of tweets. So that also seems unlikely.
Anyone have any ideas how they could possibly do it?
When you perform a search, you'll see a timeline of Tweets, Moments, and events that all match your search terms. Similarly, when you click or tap on a list, you will see an aggregated stream of Tweets (a timeline) posted by the accounts included in that list.
A likes timeline displays the most recently liked Tweets, ordered from newest to oldest, from a specific public Twitter account.
“Testing indicated that most people enjoy seeing Tweets from accounts they may not follow, based on signals such as activity from accounts you do follow, the popularity of the Tweets, and how people in your network interact with them. These experiments now inform the timeline you see today.”
Click on the three sparkling star icons on the top of the screen, to the right of the words “Latest Tweets.” Click on the option that says, “See latest Tweets instead.” Your timeline will now show you tweets as they happen, with the most recent being at the top.
Update: It’s now possible to “turn off” the timeline algorithm by turning off “Show the best Tweets first” in your settings so that tweets from people you follow are in reverse chronological order. How does the Twitter timeline algorithm work?
Twitter runs dozens of tests with its timeline every month. In fact, Deepak Rao, the product manager of the Twitter timeline, said, “Our algorithm changes on an almost daily to weekly basis”. As the Twitter timeline algorithm has helped to increase Twitter’s key metrics, it’s likely that Twitter will continue to test new ideas with its timeline5 .
The Twitter algorithm also considers how much engagement each of your tweets gets compared to your other tweets. Your most engaging posts are more likely to be boosted than those with little engagement. And if your tweets become really popular across the network, the algorithm will prioritize them even further.
Twitter’s first foray into algorithmically restructuring timelines pushed the “best tweets” to the top of people’s feeds. In an effort to be transparent, Twitter explained tweets were being scored on a relevance model that used recency, engagement, and interactions to personalize feeds.
I advice you to check the twissandra project they have implemented all the basic functionality of twitter using cassandra , a nosql database. It is said twitter is no longer using it for tweets .
The old implementation can be consulted here
I have made a video on this topic, it explains complete system design of twitter https://www.youtube.com/watch?v=KmAyPUv9gOY
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With