Skip to main content

Architectural Overview

The X For You Feed Algorithm is built on a microservices architecture with clear separation of concerns. Each component has a specific responsibility and communicates through well-defined interfaces.
The system emphasizes composability, parallelism, and graceful degradation to achieve both performance and reliability.

Component Diagram

Core Design Patterns

1. Candidate Pipeline Pattern

The Candidate Pipeline is a composable framework that defines a standard way to build recommendation systems.
The framework is built on Rust traits that define behavior contracts:

2. Parallelism Strategy

The system maximizes throughput by parallelizing independent operations:
1

Query Hydrators: Parallel

Multiple hydrators fetch different aspects of user context simultaneously:
2

Sources: Parallel

Thunder and Phoenix retrieval run simultaneously:
3

Hydrators: Parallel

All candidate hydrators enrich data concurrently:
4

Filters: Sequential

Filters must run in order since each depends on the previous filter’s output
5

Scorers: Sequential

Scorers run in order since later scorers may modify scores from earlier ones
Why Sequential for Filters/Scorers? Each filter removes candidates, affecting the input to the next filter. Each scorer may adjust scores computed by previous scorers. Dependencies require sequential execution.

3. Candidate Isolation in Phoenix

One of the most important architectural decisions is candidate isolation during ranking.
Problem: If candidates could attend to each other during transformer inference, the score for Post A would depend on which other posts happen to be in the batch. This makes scores inconsistent and uncacheable.
Solution: Custom Attention Masking
Attention Pattern:
This isolation means we can pre-compute and cache candidate scores for specific user contexts, dramatically improving inference efficiency.

4. Hash-Based Embeddings

Both retrieval and ranking models use hash-based embeddings instead of traditional vocabulary lookup tables.
Why Hashing?

Constant Memory

Embedding table size is fixed regardless of vocabulary size (users, posts, authors)

No OOV Problem

New users/posts/authors work immediately without retraining

Collision Mitigation

Multiple hash functions reduce collision impact through averaging

Sparse Features

Efficiently handles high-cardinality features like user IDs

5. Grok-Based Transformer

The Phoenix ranking model uses the Grok transformer architecture adapted for recommendations:
Key Adaptations from Grok:
Instead of text tokens, the model embeds:
  • User hash features
  • Post hash features
  • Author hash features
  • Action type (for history)
  • Product surface (mobile, web, etc.)
Rather than next-token prediction, outputs probabilities for 14 engagement actions:
Custom attention mask ensures candidates can’t attend to each other (see section above)
Input sequence format:
Where:
  • USER = User context embedding
  • H_i = History items (posts user engaged with)
  • C_i = Candidate items to rank

Data Flow Diagram

Deployment Architecture

Technology Choices

Why Rust for Backend?

Performance

Zero-cost abstractions and no garbage collection pauses

Memory Safety

Compile-time guarantees prevent crashes and data races

Async Runtime

Tokio provides efficient async I/O for high concurrency

Type Safety

Strong typing catches bugs at compile time

Why JAX for ML?

Performance

JIT compilation and XLA backend for optimized execution

Functional API

Pure functions enable easy testing and debugging

Autodiff

Automatic differentiation for training

Scaling

Easy parallelization across GPUs/TPUs

Why gRPC?

gRPC provides efficient binary serialization (Protocol Buffers), bidirectional streaming, and strong typing through service definitions.

Configuration Management

The system uses a multi-layer configuration approach:
1

Default Configuration

Hard-coded defaults in the codebase
2

Command-Line Arguments

Override defaults at startup
3

Dynamic Configuration

Runtime configuration changes through config service
  • Scoring weights
  • Filter thresholds
  • Model endpoints

Next Steps

Phoenix Deep Dive

Learn about the retrieval and ranking models in detail

Deployment Guide

Set up the system in your infrastructure

Customization

Add custom sources, filters, and scorers

Performance Tuning

Optimize latency and throughput