Skip to main content

Overview

The X Recommendation Algorithm uses Bazel as its build system. Bazel provides fast, reproducible builds and manages dependencies across the entire monorepo.
The repository includes Bazel BUILD files for most components, but not a top-level BUILD or WORKSPACE file. A more complete build and test system is planned for the future.

Understanding Bazel

Bazel is a build system that builds code from source using BUILD files that define build rules and dependencies.

Key Concepts

  • BUILD files - Define build targets and their dependencies
  • BUILD.bazel files - Bazel-specific BUILD files (used in this project)
  • Targets - A buildable unit (binary, library, test, etc.)
  • Labels - Identify build targets (e.g., //home-mixer:bin)

Common Build Rules

  • jvm_binary - Builds a JVM executable
  • jvm_app - Packages a JVM application with resources
  • scala_library - Compiles Scala source files
  • java_library - Compiles Java source files
  • py_binary - Builds a Python executable
  • rust_binary - Builds a Rust executable

Building Components

Build a Specific Component

To build a specific component, use the bazel build command with the target label:

Build All Targets in a Directory

Example: Building Home Mixer

1

Navigate to Repository Root

2

Build the Home Mixer Binary

This command:
  • Compiles all Scala source files
  • Resolves and downloads dependencies
  • Creates an executable binary
3

Locate the Output

The built binary will be in:

Building Machine Learning Models

Many ML models are in Python and located under src/python/ and component-specific directories:

Building Navi (Rust)

The Navi model serving component is written in Rust:

Testing

Running Tests

Run tests using bazel test:

Test Targets

Test targets are typically located in src/test/ directories:

Running a Test Suite

1

Find Test Targets

Query available test targets:
2

Run the Tests

3

View Test Results

Test results and logs are in:

Querying the Build Graph

Find Build Targets

Use bazel query to explore the build graph:

Visualize Dependencies

Generate a dependency graph:

Build Options and Optimization

Common Build Flags

Incremental Builds

Bazel automatically performs incremental builds by caching results:

Clean Build Cache

If you need to clean the build cache:

Building Specific Products

For You Timeline

The For You Timeline requires multiple components:

Troubleshooting

Build Failures

If Bazel reports missing dependencies, try:
Limit Bazel’s memory usage:
Clean and rebuild:
Ensure Java 11 is being used:

Performance Tips

  1. Use remote caching - If available, configure Bazel remote cache for faster builds
  2. Build specific targets - Avoid building //... unless necessary
  3. Use incremental builds - Don’t clean unless you have to
  4. Leverage parallelism - Use --jobs=auto to utilize all CPU cores
  5. Monitor build times - Use --profile to identify slow build steps

Next Steps