Book Deep-Read · Software Engineering at Google · Chapter 18
Software Engineering at Google · Ch 18 · Build Systems and Build Philosophy · Erik Kuefler · 2020
Programmers write text that people can read; computers run a different kind of file that only machines understand. The "translate and assemble" step in between is called the build. Every app on your phone, every update, has gone through it. This chapter is about how Google made that step both fast and dependable — fast enough that a one-line change comes back in seconds, dependable enough that whichever of tens of thousands of engineers runs it, the result is identical.
Ask Google engineers what they like best about the company, free food aside, and many will say: the build system. In an internal survey it ranked fourth out of 19 tools. Stranger still, it works so well precisely because it does not let engineers do whatever they want — it takes some of their freedom away.
The old way was like a handwritten recipe where each step could say anything at all. The head chef could not tell what any step really did, so they never dared let two cooks work at once, in case both grabbed the same pan; nor dared skip a step, in case it quietly used stale ingredients. So every meal was cooked from scratch, slower and slower. Worse, the recipe often only worked in the kitchen of whoever wrote it — on another computer, a missing tool or the wrong version and the dish failed.
What you get: change a little and only that little is redone; you almost never need to "wipe and start over"; a new hire can build any code on day one, and automated testing and releases can safely sit on top. The honest cost: you can no longer toss off a script that does anything you like — you play by its rules — and moving a big project already built the old way is not cheap.
Turn the build from "run a list of steps" into "declare the products you want": give up a little freedom, and the system can run in parallel, reuse results and spread work over thousands of machines — while guaranteeing the same result everywhere.
Want to see why task-based builds can't safely parallelize or go incremental, how Bazel's sandboxes and toolchains pin the environment down, how remote caching and remote execution fit together, and why strict transitive dependencies and the One-Version Rule were worth years of rollout? → Switch to the deep read
You'd think a good build system gives engineers maximum flexibility; this chapter argues the opposite: take power away from engineers and give it to the system. Once a build means "producing artifacts" rather than "running tasks", the system knows what every step does, so it can parallelize, reuse and distribute — and fast versus correct stops being a choice.
1.1.4, where a new major number signals a possibly incompatible change.The third chapter of Part IV, "Tools", following version control (Ch16, monorepo plus trunk-based development) and code search (Ch17). It is the foundation for pre-submit testing in review (Ch19), continuous integration (Ch23) and large-scale changes (Ch22); versioning is taken further in Ch21. Real-world counterparts: Bazel, Buck2, Pants, and task-based tools like Maven and Gradle.
A build system has exactly two goals: be fast (one command, often a result in seconds) and correct (anyone, on any machine, with the same inputs, gets the same output). Older tools often trade correctness for speed — shortcuts for incrementality that yield builds which sometimes work and sometimes don't.
The chapter tells the scaling story through a growing project: at first javac *.java is enough; with several languages and third-party JARs you are ordering steps by hand and stuffing downloads into a lib folder; move to shell scripts and, to avoid stale outputs, you rebuild everything every time; a disk dies and the downloaded libraries and environment variables are gone; every new hire and every nightly cron build means another round of "works on my machine". For one person writing a few hundred lines over a week or two, a compiler is all you need; once many people and many machines are involved, even a perfect script can't absorb the small differences between machines.
At Google this is pushed to the extreme: more than two billion lines of code, and even simple binaries often depend on tens of thousands of build targets. Most builds are triggered by machines, not people — changes are tested automatically in review, again before merging, and low-level library changes are verified across millions of tests. None of that works without a build you can trust.
Ant, Maven, Gradle, Grunt and Rake are task-based: the unit of work is a task, a script that can do anything, which declares the other tasks it depends on; together they form a DAG. ant dist walks dist → compile → init and then runs them in reverse — strip the syntax and it's not far from a shell script.
The root problem: the system has no idea what the scripts do, so it must be extremely conservative.
clean before every build and incrementality is dead.The conclusion is blunt: as long as arbitrary code can run during the build, the system can never have enough information to be both fast and correct.
Blaze and its descendants (Bazel, Pants, Buck) are artifact-based: a BUILD file is no longer a Turing-complete list of commands but a declarative manifest — which targets to produce, their sources (srcs), their dependencies (deps), plus a few constrained options. java_library produces a library, java_binary an executable, and deps can point within the package (:mylib), to another package in the repo (//java/com/example/common) or to a third party (@…guava//jar).
The author's analogy is functional programming: you state what to compute and leave when and how to the compiler. A build as a whole is a function from source files and tools to binaries. So:
common and only common → mylib → MyBinary rebuild while otherlib is reused — with a guarantee of no stale output.Parallelism and reuse aren't enough; each "works on my machine" hole has to be plugged:
java_library implicitly depends on a Java compiler, downloaded if missing; change the compiler and dependents rebuild. Cross-platform builds use toolchains: the concrete set of tools is picked by host and target platform.Tens of thousands of targets won't fit on one machine; cut the work small enough and spread it over any number of machines and a build gets "as fast as you're willing to pay for" — the holy grail the artifact-based design was aiming at.
Remote caching is the simple form: workstations and CI share one cache service; before building an artifact you check the cache, download it if present, otherwise build it and upload it. The precondition is fully reproducible builds, with the cache keyed on the target plus a hash of its inputs, so several people editing the same target at once don't collide. The other precondition is that downloading beats building — measure your network latency first.
Remote execution is the real distributed build: when a low-level change forces a full rebuild, a cache alone still leaves the work on your machine. A master splits requests into actions and schedules them on a scalable worker pool; workers exchange intermediate outputs through the cache. It requires a fully self-describing environment, fully self-contained steps and fully deterministic outputs — nearly impossible for a task-based system.
Google's implementation: the remote cache ObjFS stores outputs in Bigtable, and a FUSE daemon on each workstation, objfsd, makes them look like local files, downloading content only when opened — twice as fast as keeping all outputs on local disk. Remote execution is Forge: the Distributor sends actions to the Scheduler, which returns immediately on an action-cache hit and otherwise queues the action for a large pool of Executors, which write results into ObjFS. The scale: millions of builds, millions of test cases and petabytes of output every day.
Granularity is a trade-off between "one target for the whole project" and "one target per file" (see Table 2). Google favors targets much smaller than is typical in task-based systems: a typical production binary depends on tens of thousands of targets, and a moderate team owns several hundred. In Java, a directory usually holds one package, one target and one BUILD file — what Pants calls the 1:1:1 rule. Small targets mean faster distributed builds, fewer rebuilds, and running only the handful of tests a change could affect; the maintenance burden is offset by tools that manage BUILD files automatically.
Visibility is the mirror image of a dependency: for A to depend on B, B must be visible to A. Keep it narrow: only libraries meant for everyone are public, internal implementations are visible only to the team's own directories, and most BUILD files have only one non-private target.
Strict transitive dependencies: A depends on B, B depends on C — may A use C's classes directly? The linker doesn't mind, and Blaze allowed it for years. But once B is refactored and drops C, every target that "used C through B" breaks — dependencies became part of the public contract and could never be removed, so they piled up and builds slowed. Google introduced a strict mode: referencing a symbol without depending on it directly is an error, with a shell command that adds the dependency automatically. Making millions of targets declare their dependencies explicitly took years, and the author says it was well worth it: adding a dependency is a one-time cost, while implicit transitive ones keep costing for as long as the target exists. Bazel enables this mode for Java by default.
Internal dependencies are built from source at the same commit as their users, so they have no notion of "version"; external ones have versions that evolve independently of your code, and that's where the trouble lives. Three positions:
1.+ (latest with major version 1); on a multi-person project that's "a recipe for disaster" — even suppliers that claim semantic versioning can ship breaking updates, so a build that worked today breaks tomorrow with no easy rollback. With manual pins every change lives in version control and can be found and rolled back. Bazel requires all versions to be specified manually.Two further judgments: prebuilding your own code into artifacts to speed things up leaves parts of the system built from different points in the repo and hard to debug — remote caching is the better fix. Supplier risk can be handled by mirroring plus hashes, or by vendoring: Google checks every third-party library into a third_party directory at the root, but that relies on version control custom-built for an enormous monorepo.
The chapter's soul in one line: trade flexibility for scale. At each level you give up some freedom and the system gives you one more guarantee.
Table 1 · Three ways to build: how much freedom you give up, how much guarantee you get back
| Approach | Fits | You get | Honest cost |
|---|---|---|---|
| Raw compiler / shell scripts | Single-file, few-hundred-line, two-week projects; languages with a built-in build like Go | Zero setup | Not reproducible across people and machines; full rebuilds to avoid staleness |
| Task-based (Ant / Maven / Gradle) | Most small and medium projects | Automated complex builds, easier cross-machine reproduction, managed external deps | Buildfiles to write; the system can't see into tasks — hard to parallelize, unreliable incrementality, scripts hard to debug |
| Artifact-based (Blaze / Bazel / Pants / Buck) | Small to huge; inside Google everything from tiny experiments to Search uses Blaze | Safe parallelism, reliable incrementality, remote cache and execution, almost never clean | No arbitrary tasks in a real programming language; migrating an existing project is expensive and may not pay off if speed and correctness aren't yet a problem |
Table 2 · Module granularity
| Granularity | Maintenance | Build behavior | Google's choice |
|---|---|---|---|
| One target per project | BUILD file barely touched | Always built whole; no parallelism, distribution or partial caching | Lean fine: the 1:1:1 rule, production binaries depending on tens of thousands of targets; tools maintain BUILD files to offset the burden |
| One per directory (1:1:1) | Moderate | Most changes touch only a few targets | |
| One per file | Highest: every cross-file reference listed | Most flexible scheduling, caching and test selection |
Table 3 · Forks in the road for external dependencies
| Question | Easy option | The chapter's position | Price paid |
|---|---|---|---|
| How to pick versions | Latest in a range (1.+) | Manual, explicit, in version control | Every upgrade is a commit and a review |
| Multiple versions | Each target picks its own | One-Version Rule | Upgrading a library means upgrading the whole repo (see Ch21) |
| Transitive deps | Download recursively | Global file listing each one with one version | A long file that needs tooling to generate and maintain |
| Supplier availability / security | Pull straight from Maven Central | Hash checks + mirrors, or vendor into the repo | Mirrors take people to run; vendoring needs version control that can cope |
Developers build dozens or hundreds of times a day, and the build is often the rate-limiting step of their productivity. When a review asks "should we move to Bazel?", the chapter's rule is: the bigger the project, the more expensive it is to change build systems, so new projects get the best deal by starting artifact-based; for an existing large task-based project, first check whether it already has speed or correctness problems. In an interview on CI speed-ups or supply-chain security, being able to explain "cache key = target + input hash" and "reproducibility is the precondition for remote caching" goes a level deeper than "add machines, add a cache".
Industry evidence · publicly verifiable
MODULE.bazel), which resolves transitive dependencies between modules automatically using minimal version selection — no longer quite the book's "no automatic transitive dependencies"; the sandbox implementation has also evolved. A counterpoint: Bazel's learning curve is steep and tools outside its ecosystem need hand-written rules — and the author grants that task-based systems are enough for most projects.① Be fast and correct at once; once many people and machines are involved, no script can absorb the differences between machines.
② The root flaw of task-based builds is that the system can't see into arbitrary scripts: hard to parallelize, unreliable incrementality, hard-to-maintain scripts.
③ Artifact-based builds declare only targets, sources and deps and leave "how" to the system; like functional code, unchanged inputs are reused, multicore parallelism gives up to 10x, and a no-op build takes under a second.
④ Make the environment declarative too: tools as dependencies, toolchains, sandboxes, hashed external dependencies.
⑤ Remote caching requires reproducibility, keyed on target + input hash; Google's Forge + ObjFS have carried millions of builds a day since 2008.
⑥ Favor fine-grained modules (1:1:1) and narrow visibility; strict transitive deps took years to roll out because implicit dependencies are an ongoing cost.
⑦ External dependencies: pin manually, enforce one version against diamond conflicts, don't pull transitive deps automatically.
⑧ The bigger it gets, the harder it is to switch: start new projects artifact-based.