Overview
Sources are the entry point for candidates in the pipeline. They fetch raw candidates from various retrieval systems and services. All sources run in parallel to maximize throughput.Source Trait
TheSource trait defines the interface for fetching candidates:
candidate-pipeline/source.rs
fn(&self, &Q) -> bool
Optional gating logic to conditionally enable/disable the source based on query parameters
async fn(&self, &Q) -> Result<Vec<C>, String>
The main method that fetches candidates. Returns a vector of candidates or an error message.
fn(&self) -> &'static str
Returns the source name for logging and metrics. Auto-generated from the type name by default.
Thunder Source
The Thunder source fetches in-network (following) posts from the Thunder service:home-mixer/sources/thunder_source.rs
Thunder provides in-network posts from accounts the user follows. This is the “Following” content in the For You feed.
Thunder Features
- Fetches posts from accounts the user follows
- Uses the following list from
query.user_features.followed_user_ids - Returns up to
THUNDER_MAX_RESULTScandidates - Marks candidates with
ServedType::ForYouInNetwork - Includes reply chain information (ancestors)
Phoenix Source
The Phoenix source fetches out-of-network (discovery) posts from the Phoenix retrieval system:home-mixer/sources/phoenix_source.rs
Phoenix provides out-of-network posts from accounts the user doesn’t follow. This is the “Recommended” content in the For You feed.
Phoenix Features
- Fetches posts from accounts the user doesn’t follow
- Uses the user action sequence for personalization
- Conditionally disabled when
query.in_network_onlyis true - Returns up to
PHOENIX_MAX_RESULTScandidates - Marks candidates with
ServedType::ForYouPhoenixRetrieval - Requires
user_action_sequenceto be present in the query
Parallel Execution
Sources run in parallel for maximum performance:candidate-pipeline/candidate_pipeline.rs
Error Handling
Conditional Enabling
Sources can be conditionally enabled based on query parameters:- User experiments/flags
- Query parameters
- A/B test assignments
- Feature flags
Source Configuration
Typical source configuration:Best Practices
Error Messages
Error Messages
Always prefix error messages with the source name for easier debugging:
Request Validation
Request Validation
Validate required query fields before making external calls:
Candidate Metadata
Candidate Metadata
Always set the
served_type field to track candidate provenance:Stats Instrumentation
Stats Instrumentation
Use the stats macro for automatic metrics collection:
Related Topics
Pipeline Framework
Understand the overall pipeline execution flow
Hydrators
Enrich candidates after they’re fetched
Phoenix Retrieval
Deep dive into Phoenix retrieval system
Thunder Service
Thunder in-network service details