Menu
📐ByteByteGo·February 25, 2026

X (Twitter) 'For You' Feed Recommendation System Architecture

This article dissects the architecture of X's (formerly Twitter) 'For You' feed recommendation system, highlighting how it leverages a Grok-based transformer model to personalize content. It details the system's four core components: Home Mixer for orchestration, Thunder for real-time in-network post storage, Phoenix for ML-driven retrieval and ranking of out-of-network content, and the Candidate Pipeline framework for modularity. The piece emphasizes architectural choices that enable scalability, real-time performance, and a nuanced understanding of user engagement.

Read original on ByteByteGo

The 'For You' feed on X (formerly Twitter) is powered by a sophisticated real-time recommendation system. The xAI engineering team open-sourced the algorithm, revealing a system that largely replaces hand-crafted rules with a Grok-based transformer model. This architecture is designed to handle immense scale and deliver personalized content with low latency, a critical requirement for social media platforms.

Architectural Overview: Four Core Components

The system is primarily composed of four distinct components, orchestrated by the Home Mixer, and largely written in Rust and Python. This modular design facilitates independent development and scaling of different parts of the system.

  • <b>Home Mixer:</b> The orchestration layer that coordinates fetching user context, retrieving candidate posts from various sources, enriching them, filtering, scoring, and ranking to assemble the final feed.
  • <b>Thunder:</b> An in-memory post store and real-time ingestion pipeline consuming Kafka events. It provides low-latency access to in-network posts (from followed accounts) and manages data freshness with retention policies.
  • <b>Phoenix:</b> The machine learning brain. It handles both retrieval of out-of-network posts using a two-tower embedding model (User Tower, Candidate Tower) for similarity search, and ranking using a Grok-based transformer model to predict user engagement probabilities.
  • <b>Candidate Pipeline:</b> A reusable, modular framework defining the structure of the recommendation process. It provides traits (interfaces) for stages like Source, Hydrator, Filter, Scorer, Selector, and SideEffect, allowing for flexible addition of new data sources or models.

Key Design Choices for Scalability and Performance

Several architectural decisions underpin the system's ability to operate at X's scale and deliver a relevant user experience:

  • <b>Machine Learning-driven Logic:</b> The Grok-based transformer learns directly from user engagement, reducing reliance on manual feature engineering and simplifying data pipelines.
  • <b>Consistent Scoring:</b> The transformer is designed such that a post's score is independent of other posts in the same batch, making scores consistent and cacheable.
  • <b>Multi-Action Prediction:</b> Instead of a single 'relevance' score, the model predicts probabilities for various user actions (like, reply, block, mute). This fine-grained control allows the Weighted Scorer to optimize for nuanced user experience rather than just engagement.
  • <b>Modular Pipeline Framework:</b> The Candidate Pipeline framework strictly separates execution logic from business logic, enabling easy integration of new features or models without affecting the core system.
💡

System Design Takeaway

For real-time, high-scale recommendation systems, a hybrid approach combining fast, in-memory data stores for 'known' content with ML-driven retrieval for 'discovery' is highly effective. Modular pipeline designs are crucial for iterating on recommendation logic and introducing new models without system overhauls.

recommendation systemmachine learningreal-timetransformer modelsorchestrationin-memory storescalabilitymicroservices

Comments

Loading comments...