x-algorithm: The Death of the Feature Factory

How X replaced thousands of hand-engineered heuristics with a single Grok-based Transformer to power the global For You feed.

xai-org/x-algorithm

A massive, intricate clockwork machine representing the old feature factory being bypassed by a single monolithic crystal representing the Transformer. The crystal emits a clean light that organizes a chaotic storm of envelopes into a single straight line.
The transition from thousands of hand-turned dials to a single neural architecture.

Key Takeaways

The End of the Heuristic

Traditional recommendation engines are factories. Thousands of engineers spend their days manually defining what matters. They write rules to check if a post contains a video, if the user likes sports, or if the author is verified. These hand-engineered features accumulate over years, creating a fragile web of technical debt.

The x-algorithm repository represents a radical departure from this model. By open-sourcing the engine behind the X timeline, the engineering team revealed that they deleted the human element. They replaced the manual labor force of heuristics with a single Grok-based Transformer.

We have eliminated every single hand-engineered feature and most heuristics from the system. The Grok-based transformer does all the heavy lifting by understanding your engagement history (what you liked, replied to, shared, etc.) and using that to determine what content is relevant to you.

ArchitectureThe Feature Factory (Old)The Raw Data Transformer (New)
Signal Generation1000+ manual heuristicsZero manual signals
Core Tech StackScala / JVMRust / JAX
Model TypeMaskNet / Gradient Boosted TreesGrok-based Transformer
MaintenanceHigh manual tuning requiredSelf-learning via engagement logs

200 Milliseconds to Relevance

The system orchestrates a massive funnel in under 200 milliseconds. It starts with millions of posts and ends with the 100 items on your screen. This orchestration is managed by the Home Mixer, a high-throughput microservice built entirely in Rust.

When a request arrives, the Home Mixer concurrently fetches candidates from two sources. Thunder provides in-network content from accounts you follow. Phoenix fetches out-of-network content using approximate nearest neighbor search. Both streams are merged, hydrated with metadata, and sent to the scoring engine.

A 3D interactive multi-stage funnel diagram showing the flow of a user request through the recommendation engine. Top node: 'User Request'. The flow splits into two parallel nodes: 'Thunder (In-Network)' and 'Phoenix (Out-of-Network)'. These merge into a 'Hydrator' node

Phoenix: The Grok-Powered Brain

The intelligence of the system lives in Phoenix. This component abandons the traditional Wide and Deep models for a JAX and Haiku implementation of the Grok-1 architecture. The system treats a user's engagement history as a sequence, much like an LLM treats a prompt.

The model outputs a granular vector of probabilities. It does not generate a single arbitrary score. Instead, it predicts the exact likelihood of specific actions: favorite, reply, retweet, and even dwell time. A weighted scorer then collapses these probabilities into a final ranking based on business logic.

A close-up of a magnifying glass lens hovering over a simple text document. Through the lens, the text fractures into a spectrum of distinct colors, each representing a different predicted action probability.
The model looks past basic text to see a spectrum of predicted user behaviors.

The Rust Plumbing

X abandoned Scala for Rust to handle the sheer volume of concurrent network requests. The orchestration logic is built around a generic candidate pipeline framework. This uses Rust traits to define distinct stages: Source, Hydrate, Filter, Score, and Select.

This trait-based approach allows engineers to swap entirely different retrieval models without touching the core routing logic. It strictly separates the high-concurrency plumbing from the Python-based machine learning intelligence.

Closing the Loop

A recommendation engine is only as good as its feedback loop. The x-algorithm relies heavily on a decoupled side effect architecture. Once a feed is successfully served to a user, a background Rust worker logs the exact post IDs shown into a high-performance cache called Strato.

This ensures the model knows what you scrolled past without engaging. By capturing this residue asynchronously, the system trains tomorrow's model on today's implicit dismissals, all without adding a single millisecond of latency to the user's feed.