Choosing a Monorepo Build System
A monorepo build system is a decade-long commitment: migrating away is as expensive as migrating in. The right choice depends less on benchmarks than on your languages, your team and how much build engineering capacity you have.
The candidates
| Tool | Sweet spot | Languages | Cost to adopt |
|---|---|---|---|
| Bazel | large polyglot repos with native code; strict correctness; RBE | everything, best for C++, Java, Go, Python, protobuf | high: explicit BUILD files, Starlark, toolchains; a build team helps |
| Buck2 | very large repos with an RE backend; teams that want to own all rules | C++, Rust, Python, Java, Go, OCaml, Erlang… | high, plus a smaller ecosystem |
| Pants | Python-heavy repos; minimal BUILD maintenance | Python, JVM, Go, shell, Docker | medium: inference does most of the work |
| Nx / Turborepo | JavaScript/TypeScript monorepos | JS/TS first (Nx has plugins for others) | low: wraps existing package.json scripts with a task graph and caching |
| Gradle (with build cache) | JVM / Android monorepos | Java, Kotlin, Android, some C++ | low if you already use Gradle |
Native tools + CI caching (CMake + ccache, go build, Cargo workspaces) |
single-language repos of moderate size | one | lowest |
Questions that decide
python · try it yourself
def recommend(langs, native_code, team_size, ci_minutes_pain, build_engineers, mostly_js=False, mostly_python=False):
"""A deliberately simple decision helper; real decisions need a pilot."""
reasons = []
if mostly_js:
return "Nx or Turborepo", ["JS/TS repo: task-graph caching over package.json scripts is enough"]
if len(langs) == 1 and not ci_minutes_pain:
return "native tools + CI cache", ["one language and builds are not a problem yet"]
if mostly_python and not native_code:
reasons.append("Python-heavy without C++: dependency inference saves BUILD maintenance")
return "Pants", reasons
if native_code:
reasons.append("C/C++ in the graph needs real toolchain support")
if len(langs) >= 3:
reasons.append(f"{len(langs)} languages in one graph")
if ci_minutes_pain:
reasons.append("CI time is a real cost: remote caching pays back quickly")
if build_engineers == 0 and team_size > 50:
reasons.append("warning: plan for at least one build engineer before adopting")
return "Bazel (Buck2 if you already run an RE platform and want to own the rules)", reasons
cases = [
("web startup", dict(langs=["ts"], native_code=False, team_size=12, ci_minutes_pain=False, build_engineers=0, mostly_js=True)),
("ML platform", dict(langs=["python", "go"], native_code=False, team_size=40, ci_minutes_pain=True, build_engineers=1, mostly_python=True)),
("robotics", dict(langs=["cpp", "python", "go", "java"], native_code=True, team_size=300, ci_minutes_pain=True, build_engineers=0)),
("CLI tool", dict(langs=["rust"], native_code=False, team_size=5, ci_minutes_pain=False, build_engineers=0)),
]
for name, args in cases:
choice, why = recommend(**args)
print(f"{name:12} -> {choice}")
for w in why:
print(f"{'':15}- {w}")web startup -> Nx or Turborepo
- JS/TS repo: task-graph caching over package.json scripts is enough
ML platform -> Pants
- Python-heavy without C++: dependency inference saves BUILD maintenance
robotics -> Bazel (Buck2 if you already run an RE platform and want to own the rules)
- C/C++ in the graph needs real toolchain support
- 4 languages in one graph
- CI time is a real cost: remote caching pays back quickly
- warning: plan for at least one build engineer before adopting
CLI tool -> native tools + CI cache
- one language and builds are not a problem yet
Beyond the helper, ask:
- Which languages are in the same dependency graph? Polyglot graphs (a C++ library used by Python and Go) favour Bazel/Buck2; a repo that merely contains several independent projects doesn't need one build system.
- Who will own the build? Bazel and Buck2 pay off with a small build team (rules, toolchains, remote cache, CI). Without one, teams drift into
local = True, disabled sandboxes and stale BUILD files. - What hurts today? If it's CI time, a remote cache (also available for Gradle, Nx, Turborepo, sccache) may be the 80% solution. If it's correctness ("works after a clean build"), hermeticity is the feature to buy.
- What does your IDE story need? Bazel has IntelliJ and VS Code plugins and compile-database generators; check them on your real code before deciding.
- Can you pilot? Convert one vertical slice (a library, its tests, one service) and run it in CI for a month. Measure clean and incremental build times, cache hit rate and developer feedback.
Bazel vs Buck2 vs Pants at a glance
| Bazel | Buck2 | Pants | |
|---|---|---|---|
| Origin | Google (Blaze), 2015 | Meta, 2023 (Buck 2013) | Twitter/Foursquare (v1), Toolchain (v2, 2020) |
| Engine | Java server, Skyframe | Rust, DICE | Rust engine, Python rules |
| BUILD language | Starlark | Starlark | Python-like BUILD + Python plugins |
| Dependencies declared | explicitly (Gazelle helps) | explicitly | inferred from imports |
| External deps | Bzlmod + BCR | vendored / generated | lockfiles per resolve |
| Local sandbox | yes | no (RE for hermeticity) | yes (temp-dir sandboxes) |
| Remote exec | REAPI | REAPI | REAPI |
| Best at | polyglot with native code | huge repos with RE | Python |
Test yourself
A TypeScript-only monorepo wants faster CI. What's usually the right first step?
- Bazel with rules_js
- A JS task-graph tool with caching such as Nx or Turborepo
- Buck2
- Pants
Which factor most favours Bazel or Buck2?
- A single-language repo
- A polyglot dependency graph that includes native C/C++ code
- A team of three
- No CI
What should precede a company-wide migration?
- Deleting the old build
- A pilot of one vertical slice, measured in CI
- Writing all BUILD files by hand
- Buying remote execution