Welcome to the X For You Feed Algorithm
The X For You feed algorithm is a sophisticated recommendation system that combines machine learning with real-time data processing to deliver personalized content to users. This documentation provides a comprehensive guide to understanding, deploying, and customizing the system.The transformer implementation is ported from the Grok-1 open source release by xAI, adapted for recommendation system use cases.
What Makes This System Unique
The For You feed represents a modern approach to content recommendation that eliminates traditional complexity:No Hand-Engineered Features
The Grok-based transformer learns relevance entirely from user engagement sequences, eliminating manual feature engineering
Real-Time Processing
Thunder provides sub-millisecond in-network content lookups through an in-memory architecture
Multi-Action Prediction
Predicts 14 different engagement types simultaneously, from likes to blocks, for nuanced relevance scoring
Candidate Isolation
Special attention masking ensures consistent, cacheable scores independent of batch composition
Key Components
The system is built on four major components working together:Home Mixer
The orchestration layer that assembles your For You feed using a composable pipeline architectureLocation:
home-mixer/Thunder
In-memory post store with realtime Kafka ingestion for lightning-fast in-network content retrievalLocation:
thunder/Phoenix
ML component handling both retrieval (two-tower model) and ranking (Grok-based transformer)Location:
phoenix/How Content Flows Through The System
The For You feed retrieves, ranks, and filters posts from two distinct sources:- In-Network
- Out-of-Network
Thunder: In-Network Posts
Posts from accounts you follow are retrieved from Thunder, an in-memory store that:- Consumes post create/delete events from Kafka in real-time
- Maintains per-user stores for original posts, replies/reposts, and videos
- Serves candidates in sub-millisecond timeframes
- Automatically trims posts older than the retention period
The Ranking Model
Both in-network and out-of-network candidates are ranked together using Phoenix, a Grok-based transformer that:Phoenix analyzes your engagement history (what you liked, replied to, shared, etc.) to understand your interests and predict which content is most relevant to you.
Multi-Action Prediction
Rather than predicting a single “relevance” score, Phoenix predicts probabilities for 14 different actions:Technology Stack
Backend: Rust
Home Mixer, Thunder, and Candidate Pipeline are built in Rust for performance and reliability
ML: JAX + Python
Phoenix models are implemented in JAX for high-performance tensor operations
Serving: gRPC
The system exposes a
ScoredPostsService gRPC endpoint for efficient client communicationData: Kafka
Real-time post ingestion through Kafka ensures fresh content availability
What You’ll Learn
This documentation will guide you through:- Understanding the system architecture and design decisions
- Deploying the components in your infrastructure
- Customizing scoring weights and filtering logic
- Monitoring pipeline performance and debugging issues
- Extending the framework with new sources, filters, and scorers
Open Source
This project is licensed under the Apache License 2.0, making it freely available for use, modification, and distribution.Installation
Phoenix ML Models
The Phoenix models require Python 3.11+ and theuv package manager:
Install uv
Follow the uv installation guide
Dependencies are specified in
pyproject.toml and include JAX 0.8.1, dm-haiku, and numpy. uv handles all package installation automatically.Rust Components
The Home Mixer, Thunder, and Candidate Pipeline components are written in Rust:Next Steps
System Overview
Learn how the pipeline stages work together
Architecture Deep Dive
Explore the technical architecture and design patterns
Phoenix ML Models
Understand the retrieval and ranking models
Deployment Guide
Deploy the system in production