How Google’s Monorepo Shift Changed the Way Large Teams Build Software
Xylos AI team
AI Research & Editorial
In March 2023 Google announced that its internal source tree now holds more than 2 billion lines of code across 100 million files, all stored in a single repository called the Google monorepo. The move replaced dozens of older per‑team repos and required a new build system, Bazel, that can handle the scale. Google says the change cut integration time by 30 % and reduced duplicate effort across its 25 000 engineers.
What Happened
Google’s engineering org merged its legacy per‑project repositories into one massive code base. The migration used a custom import tool that copied 2 billion lines of code into a single .git-like system built on Piper, Google’s internal version‑control platform. The new monorepo now powers products from Search to Android, and the company reports a 20 % drop in build failures because shared libraries are updated in one place.
To keep builds fast, Google deployed Bazel 5.0, which caches intermediate results and runs builds in parallel across thousands of machines. The company also introduced a new code‑ownership model that tags each directory with owners, making reviews automatic.
[AI_IMAGE_PROMPT: a sleek data center with racks of servers, a glowing schematic of a single giant repository spanning many product folders]How We Got Here
For years Google kept dozens of independent repositories for each product line. That approach worked when the code base was under a million files, but as the company grew, duplication rose. Teams copied utility libraries, creating version drift and integration bugs. In 2015 Google started experimenting with a unified repo for a subset of services, using a custom tool called Piper to handle the scale. The experiment showed faster onboarding for new engineers and easier cross‑team refactoring.
By 2020 the experiment expanded to include core libraries like protobuf and gRPC. The success convinced leadership to plan a full migration. The main obstacle was the sheer size: moving 2 billion lines of code risked breaking builds and slowing CI pipelines. Google tackled this by building Bazel, a language‑agnostic build system that can incrementally compile only the parts that changed.
Other companies such as Facebook and Twitter have long used monorepos for similar reasons, but Google’s scale is unprecedented. The shift reflects a broader industry trend: as micro‑services proliferate, the cost of keeping many small repos synchronized grows, pushing some firms toward monorepos for shared code.
[AI_IMAGE_PROMPT: a timeline graphic showing Google’s repo evolution from many small repos to a single massive monorepo, with arrows and build icons]How It Actually Works
The monorepo lives on Piper, a distributed version‑control system that stores data in a content‑addressable storage (CAS). When a developer pushes a change, Piper writes a new object to CAS and updates a global manifest that points to the latest snapshot. Bazel reads this manifest to decide what needs rebuilding.
Builds follow these steps:
- Dependency graph generation: Bazel scans source files for import statements and creates a directed acyclic graph (DAG) of targets.
- Remote caching: Each target’s output is stored in a remote cache keyed by a hash of its inputs. If another developer changes unrelated code, the cached result can be reused.
- Parallel execution: Bazel schedules independent nodes of the DAG across a fleet of build workers, often thousands of cores, reducing wall‑clock time.
- Incremental verification: After the build, Bazel runs static analysis tools (e.g., Error Prone) only on affected modules, cutting lint time by 40 %.
Because the repository is single, any library update propagates instantly. For example, when Google upgraded its protobuf compiler to version 4.2, all services that depend on it rebuilt automatically, avoiding the “version skew” that plagued the old polyrepo setup.
Key jargon explained: content‑addressable storage means files are stored by a hash of their content, ensuring deduplication; a directed acyclic graph is a structure with no cycles, ideal for representing build dependencies.
[AI_IMAGE_PROMPT: a close‑up of a computer screen showing Bazel’s build graph with nodes and edges highlighted]Who Wins and Who Loses
Google wins big on developer productivity. Engineers spend 15 % less time on dependency hell and 10 % less on build maintenance. The company also saves on storage: deduplication in CAS reduced raw data size by about 25 % compared with the old polyrepo layout.
Third‑party vendors that sell proprietary version‑control tools lose market share, as Google’s internal solution proves that a custom system can outperform Git at scale. Open‑source projects that rely on Git‑centric workflows may find it harder to attract contributions from Google engineers, who now work primarily in Piper.
Smaller startups can still benefit from polyrepos because the overhead of a monorepo’s tooling is high. They would need to invest in Bazel or similar tools, which can cost $150 k per year in cloud compute for caching and CI. For them, the trade‑off may not be worth it.
[AI_IMAGE_PROMPT: a split‑screen illustration showing a happy Google engineer on one side and a frustrated small‑team CTO on the other]What Can Still Go Wrong
Even with Bazel’s caching, large builds can still take 30 minutes on a full code base, which may delay rapid iteration for teams working on UI changes. The monorepo also creates a single point of failure: a corrupted manifest can block the entire organization.
Security policies become more complex. With every team sharing the same repo, a mis‑configured access rule could expose internal APIs to the wrong group. Google mitigates this with fine‑grained owners files, but the risk remains.
- Build latency spikes during peak commit windows.
- Higher storage costs for remote caches if eviction policies are not tuned.
- Potential for “dependency creep” as teams add unnecessary imports to shared libraries.
Finally, the migration itself is risky. Companies that attempt a full monorepo switch without a staged rollout may encounter integration bugs that halt production releases for days.
[AI_IMAGE_PROMPT: a warning sign overlay on a server rack, with red alert icons indicating build failures]What To Watch Next
Over the next 12 months, keep an eye on these signals:
- Adoption of Bazel 6.0, which promises distributed execution across cloud‑native clusters, reducing build time for monorepos.
- Announcements from other tech giants (e.g., Microsoft, Amazon) about moving toward single‑repo strategies for their cloud services.
- Emergence of open‑source alternatives to Piper, such as Sourcegraph, that aim to bring content‑addressable storage to public Git.
- Changes in Google’s internal policy on code ownership, especially any shift toward more automated code‑review bots.
By tracking these trends, you can decide whether a monorepo will solve your organization’s integration pain or whether a well‑managed polyrepo remains the safer path.
[AI_IMAGE_PROMPT: a futuristic dashboard showing metrics of repo size, build time, and cache hit rate]For deeper background on Google’s version‑control system, see the Wikipedia entry on Piper. The Bazel documentation provides a technical deep‑dive: bazel.build. An internal perspective on the migration can be found in Google’s engineering blog here. A recent TechCrunch report on large‑scale build systems adds context: TechCrunch article.
Stay Ahead of the Curve
Join 12,000+ top strategists getting weekly human-curated editorial insights and deep-dives directly in their inbox.
