Book Deep-Read · Software Engineering at Google · Chapter 22
Software Engineering at Google · Ch 22 · Large-Scale Changes · Hyrum Wright · 2020
A big company's software is a huge pile of files written by tens of thousands of engineers together. Suppose one "old part" that everybody uses has to be swapped for a new one — and it's used in hundreds of thousands of places. How do you swap it? That's this chapter: how to safely pull off a "replace it everywhere" job in an enormous codebase that someone is always editing.
You'd think that the bigger the company and the better its tools, the more you can change in one go. Google found the opposite: the bigger the codebase and the more people in it, the smaller the change you can actually make and hand in all at once. So they gave up on "do it all at once" and switched to "split it into thousands of small changes and feed them in gradually."
Picture replacing the water pipes in a tower block with thousands of flats. Option one: post a notice telling every flat to replace their own pipes — nobody wants to pay for it, some will drag their feet forever, and every flat has to learn from scratch how it's done. Option two: pick a weekend, shut off the water for the whole building and swap everything at once — but there is never a moment when nobody is using water, and if something leaks halfway through, good luck finding which of thousands of joints wasn't tightened.
With this ability, many decisions that used to be "set in stone forever" — what a function is called, where a part lives — become ones you can take back. For a few dozen edits, just do them by hand; for hundreds or thousands, learn to use tools that do it in bulk. The honest cost: all of this rests on thorough automatic checks and a uniform tooling environment — old code without good tests is code nobody dares touch.
Don't expect to make a huge change in one shot: split it into many small changes that can each be checked, delivered and undone on their own, let machines do the heavy work, and let the people who know the system own it.
Want to see why atomic commits lose to scale, how Rosie shards and mails changes, how the TAP "train" saves test runs, the real numbers behind the scoped_ptr migration, and the trade-offs of global approvers and "cattle vs. pets"? → Switch to the deep read
You'd think the safest way to change a whole codebase is one atomic commit. This chapter says that as the codebase and its engineers grow, the largest feasible atomic change actually shrinks. Google's answer is to break one logical large-scale change (LSC) into thousands of pieces that can each be tested, reviewed, committed and rolled back independently, driven centrally with tooling by the infrastructure teams who understand the change — which turns many "can never change this" technical decisions into reversible ones.
The seventh chapter of Part IV, "Tools." It follows Ch21 on dependency management — Live at Head presumes that providers can fix downstream code themselves, and this chapter is about exactly that capability; it is also how Ch15's deprecations get carried out, and it leads into Ch23 on continuous integration. Real-world counterparts: company codemods, cross-repository bulk upgrades and major-version migrations.
The definition: an LSC is a set of changes that are logically related but cannot practically be submitted as a single atomic unit. That may be because there are too many files for the tooling to commit at once, because the change is so large it would always hit merge conflicts, or simply because of repository topology — across many federated repos, atomic commits may not even be possible. Motivations fall into four buckets: cleaning up common antipatterns with codebase-wide analysis, replacing uses of deprecated library features, enabling low-level infrastructure work such as compiler upgrades, and moving users from an old system to a new one.
Scale: infrastructure teams routinely need to change hundreds of thousands of references; the largest cases have touched millions. Today 10%–20% of the changes in a project come from LSCs, written by people who don't work on that project. The largest series of LSCs ever run removed more than one billion lines of code from the repository in three days. Without this capability, the codebase would atrophy under its own weight.
Why not just "ship a new class and tell everyone to migrate"? First, the expertise sits with the infrastructure team: making every team relearn it is globally wasteful, while a central team sees errors fall into a few categories and can keep a playbook. Second, nobody likes unfunded mandates: the new system's benefits are diffused across the organization, so no single team is motivated to move, and organic migrations almost never finish — new code keeps copying the old idiom. Having the team that wants the old system gone pay for the migration internalizes that externality, with economies of scale on top.
Ideally every logical change is one atomic commit that can be tested, reviewed and submitted. As the repo and its headcount grow, that ideal stops being feasible. The book lists six barriers:
Conversely, once the capability exists, even filling potholes pays off: two early Google headers, stl_util.h and map-util.h, used different separators, and engineers kept guessing wrong and waiting through a failed compile; with LSC tooling, fixing that single character took only a couple of weeks of background effort.
Codebase insight: you need both textual search and semantic analysis. The Kythe semantic index answers "who calls this function?" and "which classes derive from this one?"; ClangMR, JavacFlume and Refaster use compiler-based indices to run highly parallel transformations over the AST; small jobs can get by with sed, regexes or a shell script. The hard requirement: human effort must scale sublinearly with the codebase — generating all the changes should take roughly the same human time regardless of repo size. Rule of thumb: beyond about 500 edits, learning the generation tools usually beats editing by hand; for seasoned "code janitors" the threshold is lower.
Change management (Rosie): arguably the single most important piece — it splits the master change along project boundaries and ownership rules into shards that can be committed atomically, and runs each through its own test–mail–submit pipeline. Because Rosie is a heavy user of shared infrastructure, it caps the number of outstanding shards per LSC, runs at lower priority, and negotiates with the test platform how much load it may generate.
Testing: since a shard can contain arbitrary files, project presubmits aren't used; instead each shard runs every test in its transitive closure.
Language support: features like type aliases and forwarding functions let old and new systems coexist so users can be migrated non-atomically; languages without them are hard to migrate incrementally. Statically typed languages are far easier to change automatically than dynamic ones like Python, Ruby and JavaScript — the compiler rejects invalid transformations before tests even run. Finally, automatic formatters (clang-format, google-java-format) run as a separate pass so machine-made changes look human-written — the authors say large-scale automated changes would never have become accepted at Google without them.
Authorization: the author writes a brief document covering the reason, how many shards the change is expected to produce, and an FAQ for engineers unfamiliar with it, and gets "domain review" from the owners of the API being refactored. The proposal goes to an email list of about a dozen people who oversee the process. The committee's most common edit is to route all reviews to a single global approver. It approves liberally; the only changes it has rejected outright were dangerous (converting every NULL to nullptr) or extremely low-value (British to American spelling).
Creation: as automated as possible, so the parent change can be regenerated whenever users backslide into the old idiom or textual conflicts appear. When tools can't do it, generation can even be sharded across humans — see RoseHub in §6.
Sharding and submitting: after Rosie shards the change, each shard is tested; once it passes, Rosie picks the OWNERS member most likely to understand that shard and adds more reviewers automatically if someone is unresponsive. Project-specific checks such as change-description formatting are selectively disabled, and presubmit failures that predate the change are ignored — keeping a project free of preexisting failures is the local owners' side of the social contract with infrastructure teams.
Cleanup: "done" varies by LSC, from deleting the old system outright to migrating only high-value references. But almost every LSC needs protection against backsliding: Google uses Tricorder to flag new uses of deprecated objects at review time.
The core insight: LSCs rarely interact with one another, and most affected tests pass for most LSCs — so many changes can be tested together. That rests on two facts: LSCs are mostly narrow, semantics-preserving refactorings; and individual changes are simple and heavily scrutinized, so they are usually correct.
Shard submission uses the same idea: most shards affect fewer than a thousand tests out of millions; bigger ones are grouped — run the union first, then rerun for each shard only the tests that failed the first time. The union is often close to the entire repo already, so adding more shards is nearly free.
At scale, low-probability events become certainties: flaky tests seriously drag down LSC throughput. Google's conclusion is bold: for semantics-preserving, machine-generated changes, they are more confident in the change than in any test with recent flakiness — so recently flaky tests are ignored when submitting through automated tooling. In theory this can miss a regression that turns a flaky test into a failing one; in practice it is rare enough to handle through human communication.
Google's early C++ had a self-destructing smart pointer, scoped_ptr; C++11 introduced the strictly better std::unique_ptr, yet the codebase had more than 500,000 references to scoped_ptr spread across millions of source files — the largest LSC Google had attempted at that point. Several engineers worked in parallel for months; at the peak they were generating, testing and committing more than 700 independent changes, touching more than 15,000 files per day. The authors say they now sometimes manage 10 times that throughput.
The hard part: scoped_ptr was a parameter type in some widely used APIs, which made small independent changes difficult. They considered a call-graph analysis that would change an API and all its callers transitively in one commit, but worried that change would itself be too big to commit atomically. The final approach had three steps: make scoped_ptr a type alias of std::unique_ptr → textually substitute the old alias with the new name → finally delete the alias. It also had the typical LSC long tail: Hyrum's Law behavior dependencies, races with other engineers, and generated code the tools couldn't see, all handled by hand as testing surfaced them.
Ordinary changes are pets: an engineer spends days or weeks crafting one, and rejection stings. LSC changes must be treated as cattle: nameless, faceless commits that may be rolled back or rejected at any time — over a merge conflict or a problem tests didn't catch — at little cost unless the whole herd is affected, because the tool can be fixed and the change regenerated almost for free.
A counterintuitive finding on review: local owners trust LSC authors too much and often give only a cursory look. So Google sends shards to local owners only when their context is needed; everything else goes to a global approver — someone with approval rights across the whole repo who knows the language and library involved. They use pattern-based tooling to auto-approve changes that match expectations and inspect by hand only the small subset made anomalous by merge conflicts or tool malfunctions. Culturally, local owners can ask questions and authors answer as usual, but owners hold no veto over the LSC as a whole; a good FAQ and a long track record are what earned company-wide acceptance.
The criteria: how many places the change touches, whether the repo and environment are uniform, whether the tests can be trusted, and who understands the change best.
Table 1 · Five key decisions in an LSC
| Decision | Option A | Option B | The chapter's choice and its cost |
|---|---|---|---|
| How to commit | One atomic commit: conceptually simple, no transition period | Independent shards: each tested, reviewed, rolled back alone | Shards. Cost: you must design a transition where old and new coexist (aliases, forwarding functions), and the same tests rerun many times |
| Who migrates | Announce it; each team migrates itself | The team that owns the old system migrates centrally | Central. Cost: dedicated staff and budget — but that just internalizes an unfunded mandate's externality |
| How to create | Edit by hand | Generate with tools (AST transforms, regexes) | Tools beyond about 500 edits; human effort should scale sublinearly. Cost: upfront learning and tooling |
| Who reviews | Each project's local owners | One global approver + pattern-based auto-approval | Mechanical changes go to a global approver; only context-dependent shards go local. Cost: local teams lose their veto and must rely on trust and an FAQ |
| How to test | Run each change alone | Carpool: sample filter + union run + split on failure | The train, ignoring recently flaky tests. Cost: may miss rare regressions in theory; results take hours |
Small teams benefit too: an organization with several repos can't commit atomically across them however small it is, and the same tools scale down to a few dozen files. But an organization with many CI setups, dynamic languages and thin test coverage should first invest in a uniform environment and more tests.
The chapter's deepest payoff is at design time: if you can change the whole codebase cheaply, many decisions no longer have to be final — symbol names, class locations, even language versions can be revisited. That is why Google designs successor systems with a migration path from the old one in mind. Asked in an interview "how would you replace an interface called from thousands of places?", the answer is the three-step pattern: introduce an interchangeable new interface → migrate callers gradually → delete the old one, plus tests, sharding and a gate against backsliding.
Industry evidence · public sources
type T1 = T2, explicitly "to support gradual code repair while moving a type between packages" — the chapter's language-support requirement written into a language. golang/website · doc/go1.9.md ↗① An LSC is a set of logically related changes that cannot be submitted as one atomic unit; the more code and people, the smaller the largest feasible atomic change.
② Six barriers: VCS limits, merge conflicts, haunted graveyards, heterogeneous environments, test diagnosis, and review load.
③ The infrastructure team that owns the old system migrates centrally, internalizing the cost of an unfunded mandate.
④ Generate with tools: beyond about 500 edits, don't hand-edit; human effort should scale sublinearly, and auto-formatting makes machine changes look human.
⑤ Rosie shards by project and ownership; each shard is tested, reviewed and submitted alone, and a failure backs out only one shard — changes are cattle, not pets.
⑥ The TAP train: sample filter, carpool through a union run, split only on failure; recently flaky tests are ignored.
⑦ The three-step migration: introduce an interchangeable new interface (a type alias) → migrate → delete the old one; that is how 500,000 scoped_ptr references were replaced.
⑧ Mechanical changes go to a global approver, local owners hold no veto, and static analysis blocks backsliding afterward.
⑨ The biggest return comes at design time: technical decisions no longer have to be final.