X algorithm rewrite: Scala to Rust and a Grok transformer
- https://www.youtube.com/watch?v=-8JOlCvA4Qs
- Original title: I Can't Believe Rust is Replacing Java
xAI open-sourced the new X (Twitter) recommendation algorithm, and the repository's language stats show the decade-old Java/Scala microservice architecture is gone — only Rust and Python remain. Forrest compares the 2023 and new codebases and argues the real story isn't "Rust replacing Java": the hand-engineered features, hand-tuned weights, and dozens of interconnected Scala microservices were absorbed into a Grok-based transformer model, and Rust/Python is merely the glue that serves and orchestrates it.
The old system (2023 codebase)
- Built on Twitter's custom Scala framework Product Mixer; HomeMixer served the For You feed by orchestrating dozens of microservices: SimClusters (community data), TweepCred (reputation), RealGraph (relationship strength), EarlyBird, and more.
- "Hand-engineering": engineers explicitly added features ("did the author reply to comments?") and hand-picked weights (reply to comments +75, report a post -369), fine-tuned over years of meetings.
- Pipeline components were Scala classes extending Product Mixer traits (e.g. a
Scorertrait), with a 48M-parameter MaskNet doing inference.
The new system: four components
- HomeMixer (Rust): still serves the For You feed, but now just fetches candidates and hands them off — the orchestration logic collapsed.
- Thunder (Rust): in-memory post store for in-network candidates; needs sub-millisecond real-time serving latency, which unpredictable JVM garbage collection pauses (a random 200 ms pause mid-request) can't guarantee — the concrete technical case for Rust here.
- Candidate Pipeline (Rust): generic trait-based framework for building recommendation pipelines — the same trait-composition pattern as the Scala version, but with native async, explicit thread safety via Send/Sync bounds, zero GC overhead, and compile-time correctness instead of Scala's runtime checks.
- Phoenix (Python): the heart — out-of-network retrieval plus a Grok-based transformer that ranks posts by learning engagement patterns directly from user behavior. No more hand-tuned weights or hand-engineered features; this is also why one click on a political post floods the feed with politics.
Caveats and takeaways
- The open-sourcing is not reproducible: no model weights, no
Cargo.lockfiles (it can't even be compiled), external proto definitions — and all the interesting logic now lives inside a model we can't see. - No official engineering blog yet, but the dots connect: the codebase shrank because the intelligence moved into the model; Rust and Python exist to connect and orchestrate it. All of Elon's companies use Rust, and xAI was seemingly built on this stack from day one.
- Part of a genuine industry shift: Discord rewriting Go in Rust, Cloudflare building an nginx replacement in Rust, Rust in the Linux kernel — and now a decade of Scala microservices replaced by four components.
- The sharper question isn't whether Rust is replacing Java/Scala, but whether AI is replacing algorithms — the transformer learned to do what thousands of lines of hand-tuned code used to do, and Rust just happens to be the language people reach for as glue.
- Ends with a Brilliant sponsorship pitch (their "How AI Works" course on transformer architecture and attention).