twitter/the-algorithmPublic

Source code for the X Recommendation Algorithm

AI summary: The open-source repository containing the source code for the X (formerly Twitter) Recommendation Algorithm.

Stars
73.7K
+6 today
Forks
13.3K
Watchers
409
Open issues
323
Open PRs
192
Contributors
~3
Commits
31
Branches
1

ScalaAGPL-3.0Created Mar 27, 2023Last push 11mo ago+47 stars this week+41 this month

Star history

since Apr 24, 2022
020K40K60KApr 2022Sep 2023Feb 2025Aug 2026
73.7K stars as of Aug 7, 2026, tracked back to Apr 24, 2022. Historical curve reconstructed from public GitHub event archives, calibrated to the current total.

Contribution activity

commits per day, last 52 weeks

Signals and awards

derived from tracked data
  • Landmark project

    73,657 stars

  • Top 10% tracked

    Rank 97 of 1058

What the-algorithm does

This repository provides public access to the core components of the recommendation engine that powers the 'For You' timeline on X (formerly Twitter). It includes the machine learning models, data pipelines, and ranking algorithms used to select, score, and filter tweets for users. The codebase reveals how the platform processes user interactions, applies heuristics (like author diversity and content safety), and ultimately determines the relevance of content. It serves as a significant resource for researchers and developers interested in large-scale social media recommendation systems.

Data scientists, machine learning engineers, and researchers interested in the architecture of massive-scale recommendation systems.

  • Ranking algorithms: Includes the neural network models used to predict user engagement.
  • Candidate generation: Code for fetching potential tweets from in-network and out-of-network sources.
  • Feature engineering: Scripts defining the signals (e.g., likes, retweets, multimedia) used for scoring.
  • Filtering mechanisms: Logic for applying trust and safety filters, visibility filtering, and muting.
  • Graph processing: Implementation details of how the social graph is utilized for recommendations.

Where teams use it

Academic Research

Researchers studying the mechanics and potential biases of large-scale algorithmic timelines.

System Architecture Study

Engineers learning how to structure high-throughput recommendation pipelines.

Algorithmic Transparency

Users and policymakers auditing the factors that influence content visibility on the platform.

Model Replication

Data scientists attempting to replicate or adapt similar ranking models for other applications.

Getting started: Clone the repo and explore the documentation detailing the timeline architecture.

README

main branch

X's Recommendation Algorithm

X's Recommendation Algorithm is a set of services and jobs that are responsible for serving feeds of posts and other content across all X product surfaces (e.g. For You Timeline, Search, Explore, Notifications). For an introduction to how the algorithm works, please refer to our engineering blog.

Architecture

Product surfaces at X are built on a shared set of data, models, and software frameworks. The shared components included in this repository are listed below:

Type Component Description
Data tweetypie Core service that handles the reading and writing of post data.
unified-user-actions Real-time stream of user actions on X.
user-signal-service Centralized platform to retrieve explicit (e.g. likes, replies) and implicit (e.g. profile visits, tweet clicks) user signals.
Model SimClusters Community detection and sparse embeddings into those communities.
TwHIN Dense knowledge graph embeddings for Users and Posts.
trust-and-safety-models Models for detecting NSFW or abusive content.
real-graph Model to predict the likelihood of an X User interacting with another User.
tweepcred Page-Rank algorithm for calculating X User reputation.
recos-injector Streaming event processor for building input streams for GraphJet based services.
graph-feature-service Serves graph features for a directed pair of users (e.g. how many of User A's following liked posts from User B).
topic-social-proof Identifies topics related to individual posts.
representation-scorer Compute scores between pairs of entities (Users, Posts, etc.) using embedding similarity.
Software framework navi High performance, machine learning model serving written in Rust.
product-mixer Software framework for building feeds of content.
timelines-aggregation-framework Framework for generating aggregate features in batch or real time.
representation-manager Service to retrieve embeddings (i.e. SimClusers and TwHIN).
twml Legacy machine learning framework built on TensorFlow v1.

The product surfaces currently included in this repository are the For You Timeline and Recommended Notifications.

For You Timeline

The diagram below illustrates how major services and jobs interconnect to construct a For You Timeline.

The core components of the For You Timeline included in this repository are listed below:

Type Component Description
Candidate Source search-index Find and rank In-Network posts. ~50% of posts come from this candidate source.
tweet-mixer Coordination layer for fetching Out-of-Network tweet candidates from underlying compute services.
user-tweet-entity-graph (UTEG) Maintains an in memory User to Post interaction graph, and finds candidates based on traversals of this graph. This is built on the GraphJet framework. Several other GraphJet based features and candidate sources are located here.
follow-recommendation-service (FRS) Provides Users with recommendations for accounts to follow, and posts from those accounts.
Ranking light-ranker Light Ranker model used by search index (Earlybird) to rank posts.
heavy-ranker Neural network for ranking candidate posts. One of the main signals used to select timeline posts post candidate sourcing.
Post mixing & filtering home-mixer Main service used to construct and serve the Home Timeline. Built on product-mixer.
visibility-filters Responsible for filtering X content to support legal compliance, improve product quality, increase user trust, protect revenue through the use of hard-filtering, visible product treatments, and coarse-grained downranking.
timelineranker Legacy service which provides relevance-scored posts from the Earlybird Search Index and UTEG service.

Recommended Notifications

The core components of Recommended Notifications included in this repository are listed below:

Type Component Description
Service pushservice Main recommendation service at X used to surface recommendations to our users via notifications.
Ranking pushservice-light-ranker Light Ranker model used by pushservice to rank posts. Bridges candidate generation and heavy ranking by pre-selecting highly-relevant candidates from the initial huge candidate pool.
pushservice-heavy-ranker Multi-task learning model to predict the probabilities that the target users will open and engage with the sent notifications.

Build and test code

We include Bazel BUILD files for most components, but not a top-level BUILD or WORKSPACE file. We plan to add a more complete build and test system in the future.

Contributing

We invite the community to submit GitHub issues and pull requests for suggestions on improving the recommendation algorithm. We are working on tools to manage these suggestions and sync changes to our internal repository. Any security concerns or issues should be routed to our official bug bounty program through HackerOne. We hope to benefit from the collective intelligence and expertise of the global community in helping us identify issues and suggest improvements, ultimately leading to a better X.

Read our blog on the open source initiative here.

View on GitHub

Recent activity

commits and pull requests

Recent open issues

view all

Commits per week

last 52 weeks

When work happens

weekday and hour
SunMonTueWedThuFriSat036912151821Sun 0:00 — 0 commitsSun 1:00 — 0 commitsSun 2:00 — 0 commitsSun 3:00 — 0 commitsSun 4:00 — 0 commitsSun 5:00 — 0 commitsSun 6:00 — 0 commitsSun 7:00 — 0 commitsSun 8:00 — 0 commitsSun 9:00 — 0 commitsSun 10:00 — 0 commitsSun 11:00 — 0 commitsSun 12:00 — 0 commitsSun 13:00 — 0 commitsSun 14:00 — 0 commitsSun 15:00 — 0 commitsSun 16:00 — 0 commitsSun 17:00 — 0 commitsSun 18:00 — 0 commitsSun 19:00 — 0 commitsSun 20:00 — 0 commitsSun 21:00 — 0 commitsSun 22:00 — 0 commitsSun 23:00 — 0 commitsMon 0:00 — 0 commitsMon 1:00 — 0 commitsMon 2:00 — 0 commitsMon 3:00 — 0 commitsMon 4:00 — 0 commitsMon 5:00 — 0 commitsMon 6:00 — 0 commitsMon 7:00 — 0 commitsMon 8:00 — 0 commitsMon 9:00 — 1 commitsMon 10:00 — 0 commitsMon 11:00 — 1 commitsMon 12:00 — 0 commitsMon 13:00 — 1 commitsMon 14:00 — 0 commitsMon 15:00 — 1 commitsMon 16:00 — 0 commitsMon 17:00 — 0 commitsMon 18:00 — 0 commitsMon 19:00 — 0 commitsMon 20:00 — 0 commitsMon 21:00 — 0 commitsMon 22:00 — 0 commitsMon 23:00 — 0 commitsTue 0:00 — 0 commitsTue 1:00 — 0 commitsTue 2:00 — 0 commitsTue 3:00 — 0 commitsTue 4:00 — 0 commitsTue 5:00 — 0 commitsTue 6:00 — 0 commitsTue 7:00 — 0 commitsTue 8:00 — 0 commitsTue 9:00 — 1 commitsTue 10:00 — 0 commitsTue 11:00 — 0 commitsTue 12:00 — 0 commitsTue 13:00 — 1 commitsTue 14:00 — 0 commitsTue 15:00 — 2 commitsTue 16:00 — 2 commitsTue 17:00 — 1 commitsTue 18:00 — 0 commitsTue 19:00 — 0 commitsTue 20:00 — 0 commitsTue 21:00 — 0 commitsTue 22:00 — 0 commitsTue 23:00 — 0 commitsWed 0:00 — 0 commitsWed 1:00 — 0 commitsWed 2:00 — 0 commitsWed 3:00 — 0 commitsWed 4:00 — 0 commitsWed 5:00 — 0 commitsWed 6:00 — 0 commitsWed 7:00 — 0 commitsWed 8:00 — 0 commitsWed 9:00 — 0 commitsWed 10:00 — 0 commitsWed 11:00 — 0 commitsWed 12:00 — 0 commitsWed 13:00 — 0 commitsWed 14:00 — 0 commitsWed 15:00 — 1 commitsWed 16:00 — 1 commitsWed 17:00 — 0 commitsWed 18:00 — 0 commitsWed 19:00 — 1 commitsWed 20:00 — 0 commitsWed 21:00 — 0 commitsWed 22:00 — 0 commitsWed 23:00 — 0 commitsThu 0:00 — 0 commitsThu 1:00 — 0 commitsThu 2:00 — 0 commitsThu 3:00 — 0 commitsThu 4:00 — 0 commitsThu 5:00 — 0 commitsThu 6:00 — 0 commitsThu 7:00 — 0 commitsThu 8:00 — 0 commitsThu 9:00 — 0 commitsThu 10:00 — 0 commitsThu 11:00 — 0 commitsThu 12:00 — 0 commitsThu 13:00 — 1 commitsThu 14:00 — 0 commitsThu 15:00 — 0 commitsThu 16:00 — 0 commitsThu 17:00 — 0 commitsThu 18:00 — 0 commitsThu 19:00 — 0 commitsThu 20:00 — 0 commitsThu 21:00 — 0 commitsThu 22:00 — 0 commitsThu 23:00 — 0 commitsFri 0:00 — 0 commitsFri 1:00 — 0 commitsFri 2:00 — 0 commitsFri 3:00 — 0 commitsFri 4:00 — 0 commitsFri 5:00 — 0 commitsFri 6:00 — 0 commitsFri 7:00 — 0 commitsFri 8:00 — 0 commitsFri 9:00 — 2 commitsFri 10:00 — 1 commitsFri 11:00 — 1 commitsFri 12:00 — 0 commitsFri 13:00 — 3 commitsFri 14:00 — 2 commitsFri 15:00 — 1 commitsFri 16:00 — 0 commitsFri 17:00 — 2 commitsFri 18:00 — 0 commitsFri 19:00 — 0 commitsFri 20:00 — 0 commitsFri 21:00 — 0 commitsFri 22:00 — 0 commitsFri 23:00 — 0 commitsSat 0:00 — 0 commitsSat 1:00 — 0 commitsSat 2:00 — 2 commitsSat 3:00 — 0 commitsSat 4:00 — 0 commitsSat 5:00 — 0 commitsSat 6:00 — 0 commitsSat 7:00 — 0 commitsSat 8:00 — 0 commitsSat 9:00 — 0 commitsSat 10:00 — 0 commitsSat 11:00 — 0 commitsSat 12:00 — 0 commitsSat 13:00 — 0 commitsSat 14:00 — 0 commitsSat 15:00 — 0 commitsSat 16:00 — 0 commitsSat 17:00 — 0 commitsSat 18:00 — 0 commitsSat 19:00 — 0 commitsSat 20:00 — 0 commitsSat 21:00 — 0 commitsSat 22:00 — 0 commitsSat 23:00 — 0 commits
Commit volume by weekday and hour (UTC). Larger dots mean more commits.
DateListRankStars gained
Jan 14, 2026daily#25+133