Book Deep-Read · Software Engineering at Google · Chapter 23
Software Engineering at Google · Ch 23 · Continuous Integration · Rachel Tannenbaum · 2020
Tens of thousands of engineers push changes into the same software every day. Any one of those changes can break somebody else's work. This chapter is about how Google lets machines stand guard instead of people: every incoming change is automatically assembled and checked, and the earlier a bad change is caught, the better. That practice is called "continuous integration."
You'd think the safest approach is "before any change goes in, run every single check, and only let it in if everything passes." Google deliberately doesn't. Before a change goes in, it runs only a small handful of fast, dependable checks and lets it in first; the big checks run afterwards. If something turns out wrong, the change is undone with a click. The result is both faster and steadier.
Picture a restaurant kitchen. If every dish had to pass a full inspection before leaving the stove, cooks would spend most of their time waiting, the food would go cold, and the guests would leave. If nothing were checked, problems would surface only when a guest phoned in a complaint — by which point it's hard to tell which cook, at which step, went wrong. The later a problem is found, the harder and costlier it is to trace. Worse, some checks are themselves "sometimes right, sometimes wrong," blaming innocent cooks — and soon nobody trusts them.
Every day more than fifty thousand changes and over four billion checks pass through this system at Google, and engineers wait only about ten minutes on average to hand a change in. A small company needn't copy all of it, but it should ask how much it already pays for problems that only show up after launch. The honest cost: the checking machinery itself takes lots of machines and people to maintain, and it will never be perfectly error-free.
Continuous integration isn't "check everything, then let it in"; it's deciding "what to check, when": fast and reliable checks first, slow and difficult ones later, and undo on error.
Want to see why presubmit isn't enough, how "CI is alerting" rewrites green-build policies, the hermetic-testing and record/replay trade-offs, how TAP finds culprits among 50,000 changes a day, and Takeout's four CI makeovers? → Switch to deep read
You think CI means "run all the tests on every commit"; this chapter says CI is fundamentally a scheduling decision: which tests run when, against what kind of system under test. Fast, reliable tests go in presubmit; slow, nondeterministic ones go in post-submit and on release candidates; production gets probed with the same suite; and bad changes are handled by rollback, not by blocking. It works more like alerting shifted left than a gate that must always be green.
Part IV, "Tools," chapter eight. It follows Ch22 Large-Scale Changes (the LSC "train" runs on this chapter's TAP) and the testing chapters Ch11–14, and leads into Ch24 Continuous Delivery. Real-world counterpart: any team's CI pipeline, merge queue and pre-release test tiers.
The classic definition is Martin Fowler's: team members integrate their work frequently, each integration verified by an automated build (including tests) to detect integration errors as quickly as possible. The chapter argues that this is no longer enough: the change that breaks your application increasingly comes from an upstream microservice on the other side of a network call, from ingested data and models, from evolving operating systems and cloud platforms — released by other teams on their own schedules. Hence a second definition: CI is the continuous assembling and testing of our entire complex and rapidly evolving ecosystem.
What happens without it? Quality rests on hoping every contributor is careful. Google's scale pushes this to the extreme: one monorepo, more than 50,000 unique changes and more than four billion individual test case runs a day — on average more than one change per second. Any bad change is immediately visible to the whole company.
The later a bug is caught, the more it costs — almost exponentially. The person triaging it is less likely to know the code, the author has to dig to remember why they changed it, and the blast radius spreads from one engineer to the team and finally to users. CI's first principle is therefore fast feedback loops (also called shifting left on testing): catch each change as far left as possible.
Feedback must also be accessible and actionable. Google has a unified test-reporting system where anyone can look up any build or test run with full logs (minus user PII), plus a Google-wide statistical flake classifier — so you don't have to work out alone whether your change broke someone else's test or the test was just flaky.
The Continuous Build (CB) integrates the latest changes at head and builds and tests them, which yields two heads: true head (the latest commit) and green head (the latest change the CB has verified). Engineers often sync to green head for stability while coding, then to true head before submitting.
The first step of Continuous Delivery (CD) is release automation: continuously cutting release candidates from head (most Google teams cut at green head), then promoting each one through a series of environments with progressively larger tests. Two details matter most. First, static configuration should be promoted with the RC and tested alongside the code that uses it — the book notes that a large share of production bugs come from "silly" configuration problems. Second, RC artifacts should not be rebuilt between environments; containers and orchestration (Docker, Kubernetes, at Google usually Borg) enforce that consistency.
Why rerun on the RC the tests CB just ran? Four reasons: a sanity check that nothing odd happened when the code was cut and recompiled; auditability, since results hang off the RC; cherry-picks, which make the RC diverge from what CB tested; and emergency pushes, cut from true head with only the minimal test set. Finally, the same suite runs against production as probers: verifying production against the tests, and the tests' relevance against production. Defense in depth, not a bet on one layer.
If earlier is cheaper, why not run everything in presubmit? Three reasons. Cost: making engineers wait hours to submit is far more expensive than machines, and since tests pass far more often than they fail, dropping exhaustiveness lets you pick tests by scope or by a model predicting which will catch failures. False blame: being blocked by flakiness unrelated to your change. Mid-air collisions: while presubmit runs, the repository moves; two changes touching completely different files can together break a test. Each one is rare, but at Google's scale it happens most days. Small repositories can serialize submits to avoid it; Google cannot.
Hence the rule of thumb: presubmit gets only fast, reliable tests, typically the small tests of the project being changed. Accept some loss of coverage, catch the rest in post-submit, and accept some number of rollbacks. Whether larger tests belong in presubmit varies by team: either make them hermetic (below), or let them be unreliable in presubmit but disable them aggressively when they start failing.
In a sidebar, Titus Winters compares CI to production monitoring: both exist to identify problems automatically, as soon as possible; CI is simply alerting shifted left. That lets CI borrow SRE's hard-won policies:
A hermetic test runs against an entirely self-contained environment with no external dependencies such as production backends. It has two properties: determinism — run the same app and test code twice and get the same result, so a failure points at your code or test (system time, randomness and races can still interfere); and isolation — production problems can't affect it, and it can't affect production.
There are three tiers: fakes (cheap, but they need upkeep and have limited fidelity); a fully sandboxed stack (DisplayAds has one that starts about 400 servers from scratch on every presubmit); and, more popular for large systems, record/replay — record live backend responses, cache them, replay them hermetically. The difficulty with record/replay is the cache-hit balance: hit the cache too much and you get false positives (tests pass when they shouldn't); too little and you get false negatives (constant re-recording, often blocking submission).
Google Assistant is the success story: after making presubmit fully hermetic, runtime dropped by a factor of 14 with virtually no flakiness; before, on some days more than 50 changes bypassed and ignored test results. The price: nonhermetic tests moved to post-submit, where failures now accumulate — and some teams just disable them.
Assistant also exploits its move to microservices for post-submit failure isolation: for each of N microservices, an environment runs that service built at head alongside production (or near-production) versions of the other N−1, so a failure isolates to the newly built server. Naively that costs O(N²) servers (N environments × N services each); with hotswapping — a request can tell a server to call a different backend address — only N head-built servers are needed, all reusing the same production backends, cutting cost to O(N).
TAP (Test Automation Platform) is Google's global continuous build, the gateway for almost every change. Its core bet is optimistic integration: each team defines only a fast subset of tests (usually unit tests) as presubmit; empirically, a change that passes presubmit has a 95%+ chance of passing everything else, so it's let in for others to use, while larger, slower tests run asynchronously after submission. The average wait to submit is around 11 minutes, often in the background.
The price of letting changes in is that bad ones land, so two things come with it. Culturally, committing new work on top of known-failing tests is strongly discouraged. Organizationally, each team has a Build Cop responsible for keeping the project's tests passing no matter who broke them: when notified, they drop everything, find the offending change, and prefer rollback — fixing forward is riskier. Any change can be rolled back with two clicks, and TAP now auto-reverts when it's highly confident about a culprit. The book puts it neatly: tests give us confidence to change; rollbacks give us confidence to undo — neither works without the other.
Culprit finding is hard: there are too many changes a day for TAP to run every test on every change, so it batches related changes, which obscures which one broke a test. TAP automatically splits a failing batch and reruns each change in isolation, and developers have tools to binary-search a batch. On resources, most tests run on the distributed build-and-test system Forge; Forge and Blaze maintain a near-real-time global dependency graph, from which TAP runs only the minimal set of downstream tests. A neat incentive: changes that trigger fewer tests get scheduled sooner — on a busy day, 100 versus 1,000 triggered tests can mean tens of minutes of difference — nudging engineers toward small, focused changes.
Google Takeout began in 2011 as a data export product and became a platform: APIs for at least 10 other products, and 90+ product plug-ins. Each scenario leaves one reusable practice:
One criterion: how fast, how stable and how high-fidelity a test is decides which slot in a change's life it belongs in.
Table 1 · Five key CI choices
| Decision | Option A | Option B | The chapter's pick and its cost |
|---|---|---|---|
| When to block | Run every test in presubmit; land only if all pass | Only fast tests in presubmit; the rest after landing | B: 95%+ of changes that pass the fast tests pass everything. Cost: bad changes land, so you need Build Cops and fast rollback |
| Submit order | Serialize submits; no mid-air collisions | Concurrent submits; accept collisions | Small repos pick A; at Google's scale only B, backstopped by post-submit |
| Test backends | Live backends: highest fidelity | Hermetic: fakes / sandboxed stack / record-replay | Hermetic in presubmit (Assistant 14× faster), live kept for post-submit. Cost: resources and upkeep; record/replay struggles to balance false passes and false failures |
| When it's red | Freeze all commits until green | Find the root cause; roll back or disable with a bug | B, "CI is alerting." Cost: discipline needed so disabled tests don't pile up |
| Flaky tests | Allow multiple attempts | Pull from presubmit temporarily, track the fix | Google uses both, with platform-level flake statistics. Cost: retries mask real bugs; removal loses coverage (see Kubernetes in §6) |
"We can't afford CI"? The book's answer: count what you already pay for problems that surface only in production. CI isn't a new cost; it's the same cost shifted left to a cheaper stage.
The chapter redefines CI from "a tool" into a scheduling problem. Asked in an interview how to design CI for a large team, the answer isn't "run everything every time" but tiers: fast and reliable presubmit; post-submit with dependency-graph test selection, batching and automatic culprit finding; RC promotion through environments; production probers as the last line — plus a Build Cop and one-click rollback.
Industry evidence · publicly verifiable
crbug.com/NNNN bug on the line — the same idea as Takeout's "tag with a bug, then disable." chromium/chromium · docs/testing/web_test_expectations.md ↗flakeAttempts=2 was dropped as of 2019-12-13 and confirmed as policy in 2023 — and quarantining a flaky test requires an issue labeled priority/critical-urgent. kubernetes/community · sig-testing/flaky-tests.md ↗① CI's modern definition: the continuous assembling and testing of a whole fast-moving ecosystem; at its core, deciding which tests run when, against what system under test.
② Bugs cost more the later they're caught, so build fast feedback loops whose results are accessible and actionable.
③ Presubmit can't be greedy: cost, false blame from flakes, mid-air collisions. Rule of thumb: only fast, reliable tests.
④ The repo has a true head and a green head; RCs are usually cut at green, static config is tested with the RC, and artifacts aren't rebuilt across environments.
⑤ Rerun tests on the RC for sanity, audit, cherry-picks and emergency pushes; run them again on production as probers.
⑥ CI is alerting shifted left: a flaky test is a false page; chasing 100% green is as costly as chasing 100% uptime.
⑦ Hermetic tests buy determinism and isolation (Assistant: 14× faster); record/replay is a balancing act between false passes and false failures.
⑧ TAP: 50,000+ changes and 4B+ test cases a day; optimistic landing + Build Cop + rollback first + batch splitting and bisection + dependency-graph test selection.
⑨ Disable failing tests only with a bug attached, tracked and auto-cleaned — the suite stays green without forgetting known issues.