Design a Build System for a Billion-Line Monorepo
A Staff-level walkthrough of a Blaze/Bazel-style build system that turns a 30-minute local build of a billion-line monorepo into a two-minute one — built on a content-addressable remote cache, hermetic distributed execution, and dependency-graph test selection. The recurring tension is hit-rate and parallelism versus correctness, where under-selecting tests can silently ship regressions. Follow it top to bottom, or jump to any step.
Scope & ambiguity
“Google’s monorepo has 1B+ lines of code with 50K+ engineers making 60K+ commits/day. The key challenge is making builds fast and reproducible at this scale. I’ll focus on remote caching, distributed execution, and test selection — the three pillars that make it possible to build from a 1B-line repo in minutes instead of hours.”
Teams: Build Infrastructure Team (build engine, caching), Execution Team (distributed build workers), Developer Experience Team (IDE integration, local development), CI/CD Team (continuous builds, presubmit checks).
Requirements
Back-of-envelope estimation
Cost
Business justification: If builds took 10 minutes instead of 2, 50K engineers × 10 builds/day × 8 min wasted = 66K engineer-hours/day. At $100/hr, that’s $6.6M/day. The build system pays for itself many times over.
Architecture
Deep dives
WHERE STAFF IS WONContent-Addressable Remote Cache
Distributed Execution
Test Selection (Impact Analysis)
Build vs Cloud Build Tradeoffs (Developer Laptop)
Rollout & evolution
Rollout: Migrate teams from existing build system incrementally. Run both systems in parallel, compare build times and correctness. Language by language (C++ first, then Java, Python, Go).
Evolution: Year 1: Remote caching + distributed execution, 95% cache hit rate. Year 2: ML-based test selection (learn from historical test results which tests are most likely to fail), build performance analytics (identify slow targets, suggest optimizations). Year 3: Self-service build rules (teams define custom build rules without infra team), build cost attribution per team, integration with code review (show build/test results inline).
Rubric — Senior vs Staff
Want more breakdowns like this?
Join free early access for upcoming RAG, LLM eval, agents, and AI infrastructure walkthroughs.