The one-line change that broke three apps
A team I know shipped a small fix to a shared login library on a Friday afternoon. The change was two lines. It passed its own tests. On Monday, three different products were broken: the web app, the mobile app, and an internal admin tool, all of which depended on that library. Each product lived in its own repository, each pinned a different version of the library, and nobody had a clear picture of which version was running where. The fix was rolled back, the three teams spent a week coordinating, and the library was eventually republished with a new version number — which two of the three products then forgot to upgrade to.
This is the problem monorepos are built to solve. A monorepo — short for monolithic repository — keeps many projects in a single version-controlled repository instead of splitting each one into its own. Google, Meta, Microsoft, and Uber all run some of the largest monorepos in the world, holding millions of lines of code and thousands of engineers' work in one place. The idea sounds simple, and in some ways it is. But the simplicity is deceptive. A monorepo is not just a folder with everything in it. It is a way of organising code, tooling, and teams, and it works brilliantly for some organisations and badly for others.
What a monorepo is — and what it is not
At its simplest, a monorepo is one repository containing multiple projects: several applications, shared libraries, tools, and configuration, all versioned together. A single commit can change a library and every application that uses it. There is one version of the truth about what code is running, because there is only one copy of each file.
That is different from a polyrepo setup, where each project has its own repository and shared code is distributed as versioned packages — the way most teams using npm, Maven, or PyPI work. In a polyrepo, changing a shared library means publishing a new version, then updating each consumer separately, then waiting for each consumer to upgrade. That works fine at small scale. At large scale, it becomes the Friday-afternoon story above: versions drift, upgrades get forgotten, and a bug fix in a library can take weeks to reach every product that needs it.
A monorepo is also not the same thing as a single big application. A monorepo usually contains many applications and many libraries that are deployed independently. Nor is a monorepo the same as a monolith in the architectural sense. A company can have a monorepo full of microservices, and a company can have a single monolithic application split across many repositories. The repository layout and the system architecture are separate decisions, and confusing them is one of the most common mistakes in this whole discussion.
The key property of a monorepo is atomic change: one commit, one review, one test run can span the library and all its consumers. When the login library changes, the web app, the mobile app, and the admin tool change in the same commit, and the tests for all four run together. Nothing is left behind on an old version, because there are no versions between projects in the same repository. That is the whole point, and it is also the source of most of the difficulties.
Why the biggest companies run monorepos
Google's monorepo is the most famous example. It holds the code for Search, Gmail, YouTube, Android, and nearly everything else the company builds, in a single repository that has been growing since the late 1990s. Meta runs a similar setup for Facebook, Instagram, and WhatsApp. Microsoft moved Windows development into a single Git repository. These companies did not choose monorepos for fashion. They chose them because, at their scale, the polyrepo alternative had become unworkable.
The first reason is shared code. A large company has hundreds of libraries that many teams use: logging, authentication, data access, user interface components, build tooling. In a polyrepo world, each of those libraries has a version number, a release process, and a set of consumers that may or may not have upgraded. In a monorepo, a library change is visible to everyone immediately, and the author of the change is responsible for fixing every consumer that breaks. That sounds harsh, and it is — but it is also honest. The breakage exists either way. In a polyrepo it is discovered later, by someone else, in production.
The second reason is code discovery and reuse. In a monorepo, any engineer can search the entire codebase and find the code they need. They can see how another team solved a similar problem, and reuse that solution instead of writing their own. In a polyrepo world, code in another repository is effectively invisible unless you already know it exists. The result, at large companies, was dozens of teams each writing their own slightly different version of the same thing.
The third reason is tooling. When all the code is in one place, the company can build one set of tools — one build system, one test runner, one code review flow — and apply it everywhere. Google's Bazel build system, which grew out of its internal tool Blaze, exists because the monorepo made it possible and necessary. A single tool that understands the whole dependency graph can build only what changed, test only what is affected, and cache results across the whole company.
The fourth reason is simpler than the others and easy to underestimate: refactoring. Renaming a widely used function, changing an API, or moving a module is a single operation in a monorepo. In a polyrepo, the same change is a project: update the library, publish it, update each consumer, coordinate the releases, and hope nobody missed one. Large-scale refactoring across a polyrepo is so painful that teams simply stop doing it, and the codebase slowly hardens into a shape nobody would choose today.
The tooling that makes a monorepo work
A monorepo without the right tooling is just a very large folder, and a very large folder is a bad place to work. The tools exist to solve the problems that scale creates: slow builds, slow tests, and the sheer difficulty of finding anything.
Build systems are the foundation. Bazel, originally Google's internal Blaze, understands the dependency graph of the whole repository and rebuilds only what changed, caching everything else. Nx, built for JavaScript and TypeScript workspaces, does something similar for the web ecosystem: it tracks which projects depend on which, runs only the tasks affected by a change, and caches results locally and remotely. Turborepo, now part of Vercel, offers a lighter version of the same idea, focused on JavaScript monorepos with fast incremental builds. For teams that do not need that level of sophistication, package manager workspaces — npm workspaces, Yarn workspaces, or pnpm workspaces — provide the basic structure: one lockfile, shared dependencies, and the ability to link local packages together without publishing them.
The single most important feature of any monorepo tool is affected computation: the ability to work out, from a change, which projects are affected and run only their tests and builds. Without it, every commit triggers a build of everything, and the build time grows with the repository until nobody can get anything done. With it, a change to one small library triggers the tests for that library and its direct consumers, and nothing else. Google's infrastructure does this at enormous scale; Nx and Turborepo bring a version of it to ordinary teams.
Versioning works differently in a monorepo, and this is where many teams stumble. There are two main approaches. Fixed versioning means every package in the repository shares one version number, and every release bumps them all together. This is simple and it is what tools like Lerna's fixed mode do, but it means a patch to one library produces a new version of everything, including projects that did not change. Independent versioning means each package has its own version, bumped only when it changes — closer to how polyrepos work, but with the changes still happening atomically. Most teams settle on independent versioning for libraries they publish, and fixed versioning for applications that are deployed together. There is no single right answer, and the choice should follow from how the code is actually released, not from what a tool's defaults suggest. For more on how versioning decisions ripple through a release, see the article on API versioning.
Code ownership is the other piece of tooling that matters. In a monorepo, anyone can technically edit anything, which is both a strength and a risk. The CODEOWNERS file, supported by GitHub, GitLab, and other hosts, maps directories to the teams that own them, so that a change to the payments code automatically requests review from the payments team. Without ownership rules, the shared repository becomes a commons where nobody feels responsible for any particular part, and quality drifts. With them, the monorepo keeps the benefit of cross-team visibility while preserving accountability.
What changes for the developers working in one
For an individual developer, the daily experience of a monorepo is mostly better, with a few sharp edges. The good parts are immediate. Finding code is easier: one search covers everything. Trying a change that spans two projects is easy: edit both, run the tests, submit one review. There is no waiting for a library to be published, no version bump, no pull request in a second repository. A new developer clones one repository and has everything they need, instead of cloning five repositories and working out how they fit together.
The sharp edges are real, though. The first is repository size. A monorepo with years of history can be enormous, and cloning it can take a long time. The standard answers are partial clone and sparse checkout, features in modern Git that let a developer download only the parts of the repository they actually work on. GitHub and GitLab both support these, and Microsoft built its Scalar tool specifically to make large Git repositories usable. A team that adopts a monorepo without setting these up will hear about it from every new hire within a week.
The second edge is build and test speed. Even with affected computation, a large monorepo's test suite is big, and a developer who runs the full suite locally will be waiting a long time. Remote caching — where build and test results are shared across the team so that a developer never rebuilds something a colleague already built — is the answer, and it is one of the main things tools like Nx and Bazel sell. It requires infrastructure: a cache server, and the discipline to keep it working.
The third edge is the blast radius of a bad change. In a polyrepo, a broken library release affects only the teams that upgrade to it, and they can pin the old version. In a monorepo, a bad change to a shared library breaks every consumer at once, and there is no old version to fall back on. This is the honest trade-off at the heart of the design: the monorepo makes breakage visible immediately and makes it everyone's problem, which is exactly why it works — but it also means a careless change can stop a whole organisation. Strong tests on shared libraries, and a culture of running the affected tests before merging, are not optional extras. They are the safety net the whole structure depends on.
When a monorepo hurts
Monorepos are not a universal answer, and the teams that adopt them for the wrong reasons usually regret it. The first warning sign is a team that does not actually share code. If the projects in the repository rarely depend on each other, the monorepo adds coordination cost without giving anything back. Each project still deploys independently, still has its own release cycle, and still has its own team — and now they all share a build system, a set of tooling decisions, and a repository that is larger and slower than any of them needs. Separate repositories would have been simpler.
The second warning sign is teams that need to move at very different speeds. A startup's experimental product and a bank's regulated payments system do not want the same release process, the same review rules, or the same deployment pipeline. Forcing them into one repository means either the experimental product inherits the bank's process, or the bank's process gets watered down to fit the experiment. Neither is good. Polyrepos let each team choose its own pace. Monorepos work best when the teams in them share a broadly similar way of working.
The third warning sign is access control. Some code cannot be visible to everyone. A repository that holds both open-source code and proprietary code, or code subject to different legal restrictions, needs careful access control, and most monorepo setups are built on the assumption that everyone can see everything. It is possible to restrict parts of a monorepo, but it is awkward, and it fights the tooling. If a significant part of the codebase cannot be shared, the monorepo's main advantage — visibility — is gone for that part.
The fourth is tooling maturity. A monorepo without affected computation, remote caching, and ownership rules is a liability, not an asset. A team that adopts the repository layout without the tooling will find builds getting slower every month, and will eventually conclude that monorepos do not work — when what actually happened is that they adopted half the idea. The honest question before migrating is whether the team is willing to invest in the tooling and the discipline it requires. If the answer is no, the polyrepo setup they already have is probably the better choice.
There is also a cultural point that rarely appears in tooling discussions. A monorepo works when teams feel responsible for the code they touch, even when it belongs to another team. The Google model — you break it, you fix it — depends on engineers who are willing to update another team's code when their change affects it, and on teams that accept outside changes gracefully. In an organisation where teams guard their code jealously, or where a change to another team's code is treated as an intrusion, the monorepo will generate friction instead of speed. The repository layout cannot fix a culture problem.
Moving from many repos to one
Migration is a project in its own right, and the teams that do it well do it gradually. The common pattern is to start with the code that is most shared: the libraries and the applications that depend on them. Move those into a single repository first, set up the build tooling, and let the team learn how it feels. The remaining repositories can follow over months, or never — a hybrid setup, with a monorepo for the core products and separate repositories for the outliers, is a perfectly reasonable end state.
The more important part of the migration is the human one. Developers need to know how to work in the new setup: how to run the affected tests, how to make a change that spans projects, who reviews what. A short guide, a few worked examples, and someone available to answer questions in the first month will do more for adoption than any tooling choice.
A few things people get wrong
The first misconception is that a monorepo means one version of everything. It does not. The applications in a monorepo can deploy different versions of a library if they need to — the repository is shared, but the deployments are not. What the monorepo guarantees is that the source is shared, so a fix can reach every consumer in one commit. Whether each consumer deploys that fix immediately is a separate decision.
The second misconception is that monorepos are only for huge companies. They are not. Small teams benefit too, sometimes more: a team of five building a web app, a mobile app, and an API from a shared set of libraries gets the same atomic-change benefit Google gets, at a fraction of the tooling cost. The tools that make this practical for small teams — Nx, Turborepo, pnpm workspaces — are free and take an afternoon to set up. The question is not team size. It is how much the projects share, and how often changes span more than one of them.
The third misconception is that a monorepo eliminates versioning problems. It moves them, rather than eliminating them. Instead of version drift between repositories, a monorepo team deals with the problem of coordinating a breaking change across many consumers at once, and with deciding when a library's public API can change. Semantic versioning still matters for libraries that are published externally. Inside the repository, the version is the commit, and the discipline is in the tests.
The fourth misconception is that monorepos and microservices are opposed. They are not. A monorepo can hold a hundred microservices, each deployed independently, and that is exactly how several of the largest companies run their systems. The repository is about how code is stored and changed. The architecture is about how it runs. Mixing the two up leads to the strangest arguments in this whole debate — including the claim that a monorepo forces a monolithic architecture, which it plainly does not. For a related look at how debugging changes when code spans many services, see the article on debugging.
What to do next
If you are considering a monorepo, start with an honest count. How many projects does your team actually maintain, and how often does a change span more than one of them? If the answer is "rarely", stop here — a monorepo will cost more than it saves. If the answer is "every week", the case is strong.
Then run a small experiment. Take two projects that share a library, put them in one repository with a workspace setup, and work in it for a month. Pay attention to the things that matter: how long a cross-project change takes, how often the tests catch a breakage that would previously have shipped, and how the developers feel about the setup. A month of real work will tell you more than any amount of reading.
If the experiment works, invest in the tooling before you scale up: affected computation, remote caching, ownership rules, and sparse checkout for new developers. And agree on the social rules — who fixes a broken consumer, how breaking changes are handled — before the repository grows past the point where those rules can be changed easily.
A monorepo is a bet that the cost of coordinating shared code is lower when the code is in one place than when it is spread across many. For teams that share a lot of code and change it often, that bet pays off many times over. For teams that do not, it is an expensive way to learn that the simplest structure is the one they already had. The difference is not in the tooling, or the size of the company, or the fashion of the moment. It is in how the code actually moves, week by week, between the people who write it.
Comments
Post a Comment