Overview
This guide will help you set up your development environment to work with X’s Recommendation Algorithm. The codebase is a complex, production-scale system written primarily in Scala, with components in Java, Python, and Rust.Prerequisites
Before you begin, ensure you have the following installed:1
Install Java Development Kit (JDK)
Install JDK 11 or later. The project uses Java 11 as the runtime platform.
2
Install Bazel
The project uses Bazel as its build system. Install Bazel following the official installation guide.Verify your installation:
3
Install Scala (Optional)
While Bazel manages Scala dependencies, you may want to install Scala for IDE support.
4
Install Python
Some components require Python 3.7 or later for machine learning models and scripts.
5
Install Rust (for Navi)
The Navi model serving component is written in Rust.
Clone the Repository
Clone the X Recommendation Algorithm repository:Repository Structure
Understanding the repository structure will help you navigate the codebase:Core Data Services
- tweetypie/ - Core service for reading and writing post data
- unified_user_actions/ - Real-time stream of user actions
- user-signal-service/ - Centralized platform for user signals (likes, replies, clicks)
Models and Algorithms
- src/scala/com/twitter/simclusters_v2/ - SimClusters community detection
- trust_and_safety_models/ - NSFW and abusive content detection
- src/scala/com/twitter/interaction_graph/ - Real-Graph user interaction predictions
- src/scala/com/twitter/graph/batch/job/tweepcred/ - TweepCred reputation algorithm
Software Frameworks
- navi/ - High-performance ML model serving (Rust)
- product-mixer/ - Framework for building content feeds
- timelines/data_processing/ml_util/aggregation_framework/ - Feature aggregation
- representation-manager/ - Embedding retrieval service
- twml/ - Legacy ML framework (TensorFlow v1)
Product Surfaces
- home-mixer/ - Main service for Home Timeline (For You, Following, Lists)
- pushservice/ - Recommendation service for notifications
- tweet-mixer/ - Coordination layer for out-of-network tweet candidates
- follow-recommendations-service/ - Account and post recommendations
Candidate Sources and Ranking
- src/java/com/twitter/search/ - Search index for in-network posts
- src/scala/com/twitter/recos/ - GraphJet-based recommendation services
- timelineranker/ - Legacy ranking service
- visibilitylib/ - Content filtering and compliance
Source Code Organization
- src/java/ - Java implementations
- src/scala/ - Scala implementations
- src/python/ - Python ML models and scripts
- src/thrift/ - Thrift service definitions
IDE Setup
IntelliJ IDEA (Recommended for Scala/Java)
1
Install IntelliJ IDEA
Download and install IntelliJ IDEA (Community or Ultimate edition).
2
Install Plugins
Install the following plugins:
- Scala
- Bazel (by Google)
3
Import Project
- Open IntelliJ IDEA
- Select “Open” and choose the repository root directory
- When prompted, import as a Bazel project
- Configure the project SDK to use Java 11
Visual Studio Code
1
Install VS Code
Download and install Visual Studio Code.
2
Install Extensions
Install the following extensions:
- Scala (Metals)
- Bazel
- Python
- rust-analyzer (for Navi)
3
Open Project
Open the repository root directory in VS Code. Metals will automatically detect the Scala code and provide IDE features.
Verify Your Setup
Test your development environment by checking if you can query the build targets:Next Steps
- Learn about building and testing the codebase
- Review the contributing guidelines
- Explore the engineering blog for algorithm details