Monorepositories: One Source of Truth or One Big Mess?

If a company has twenty software projects, should it also have twenty repositories?

At first, the answer seems obvious. A repository is cheap. Each team gets its own, the boundaries are clear and nobody needs to see code that does not concern her.

Then the projects start sharing code.

One team copies a useful helper. Another publishes a shared library. A third team needs a small change that is incompatible with the existing version. A few months later nobody knows which copy is authoritative, and updating the library requires a coordinated release campaign across half the company.

Maybe putting everything into one repository would be easier?

TL;DR A monorepository can simplify dependencies, collaboration and large-scale changes. It can also make bad dependencies, slow builds and a broken main branch everybody’s problem. Its benefits only materialize if tooling, code health and engineering culture keep up with the size of the codebase.

I have decided to consolidate my internal software, websites, and DevOps environments into a single mono-repository. There are advantages, and disadvantages, and even as a single person I have had difficulties keeping the codebase consistent. The following discusses the generic situation, and then I conclude with my own experience.

What Is a Monorepository?

A monorepository, usually shortened to monorepo, stores the source code of many projects in one repository. These projects may include applications, services, shared libraries, build tools and infrastructure.

This does not mean that the software itself is a monolith. A single repository may contain hundreds of independently deployed services with carefully designed interfaces between them. Repository boundaries and architectural boundaries are two different things.

That distinction is important. Putting two modules next to each other neither makes them independent nor tightly coupled. The dependencies between them do that.

One Source of Truth

The most obvious advantage of a monorepo is that there is one authoritative version of every file.

There is no need to fork a shared library just because another team needs a small variation. There are no copied helpers whose bug fixes must somehow be merged across five repositories. Developers can find existing code and examples instead of unknowingly solving the same problem again.

The directory tree also provides a common map of the software landscape. Directories can represent products, services or teams, while ownership rules determine who must review a change. Teams can be reorganized without first moving their code through a succession of repository migrations.

Unified versioning does not mean that every product must have the same release number or be deployed at the same time. It means that one commit identifies a compatible state of the complete source tree.

And that makes dependency management interesting.

The Diamond Dependency Problem

Assume application A depends on libraries B and C. Both libraries depend on a base library called D.

So far, everything is fine.

Now B requires version 1 of D, while C has already moved to an incompatible version 2. Depending on the language and package manager, it may become impossible to build A. Releasing a new version of D may require a carefully choreographed sequence of updates to B, C and finally A.

flowchart LR
    subgraph OK["Compatible dependency diamond"]
        direction TB
        A1["Application A"]
        B1["Library B"]
        C1["Library C"]
        D0["Base library D"]

        A1 --> B1
        A1 --> C1
        B1 --> D0
        C1 --> D0
    end

    subgraph CONFLICT["Conflicting dependency versions"]
        direction TB
        A2["Application A"]
        B2["Library B"]
        C2["Library C"]
        D1["Base library D — v1"]
        D2["Base library D — v2"]

        A2 --> B2
        A2 --> C2
        B2 --> D1
        C2 --> D2
        D1 -.-|"incompatible"| D2
    end

In a monorepo, the change to D and the necessary adaptations to B, C and A can be made in one commit. Either the entire change passes its checks or none of it enters the main branch.

The monorepo does not magically remove the dependency graph. It makes that graph visible and allows the organization to update it atomically.

Change Everything at Once

An atomic change is one of the strongest arguments for a monorepo.

If a shared API changes, its implementation and all callers can be updated together. There is no need to publish an intermediate library release, wait for every consumer to migrate and keep the old API alive until the slowest project catches up.

Atomic does not mean small. It means indivisible.

This becomes particularly useful for large-scale modernization. A specialist team can update a language feature throughout the codebase, replace a deprecated API or correct a design mistake wherever it occurs. Once all usages are known, obsolete code can be removed with much greater confidence.

The fix can also be accompanied by a compiler warning, lint rule or presubmit check that prevents the old pattern from returning. You do not merely clean up the code. You teach the codebase to remain clean.

Collaboration Without Repository Borders

Separate repositories create strong boundaries. Sometimes that is exactly what we want. Sometimes it is merely an accident of where someone created a Git repository five years ago.

A monorepo makes code visible across team boundaries. Developers can discover an existing library, inspect how other projects use an API and contribute a fix without first negotiating a release between repositories.

This also makes team boundaries more flexible. Code ownership can follow the directory structure without making the repository itself the organizational chart.

However, visibility is not the same as permission, and proximity is not the same as a good dependency.

This is where the trouble starts.

The Bill for the Convenience

The complexity that disappears from cross-repository releases does not vanish. It moves into the repository, the build system and the engineering rules.

Slow Git Operations and Expensive Pipelines

As a repository grows, ordinary Git operations may become slow. Cloning, updating and inspecting a repository containing the work of an entire company is different from doing the same with a small application.

The naive CI pipeline is even worse:

  1. Someone changes one line.
  2. The pipeline builds every project.
  3. Every test runs.
  4. Everyone goes for lunch.

To remain productive, a large monorepo needs tooling that understands the dependency graph. It must identify affected projects, cache unchanged results and avoid doing the same work repeatedly. Developing those tools costs money. Running computationally expensive builds and tests costs money as well.

Google has demonstrated that a monorepo can scale to an enormous codebase. It has also demonstrated that doing so requires substantial investment in scalability and developer tooling. The first fact is often quoted. The second one is the more important lesson.

One Broken Branch, Many Unhappy Teams

If the main branch of a small repository is broken, one project is blocked. If the main branch of a company-wide monorepo is broken, the blast radius is much larger.

Strong presubmit checks, fast feedback and reliable tests are therefore not optional niceties. The larger the repository, the more expensive a fragile test or unreliable pipeline becomes.

There is also more noise. Developers may see commits, notifications, test results and code-search matches from projects they never touch. Tools and permissions must provide useful views of the repository without pretending the rest of it does not exist.

Dependencies Become Too Easy

A monorepo encourages code sharing and reuse. Unfortunately, it can encourage too much of it.

If importing another internal module takes one line, developers will do it. Soon a tiny utility depends on a large library, which depends on three more libraries, and a harmless change breaks an application whose developers did not even know the utility existed.

Unnecessary dependencies increase build and test time, and maintenance cost. In particular, a build failure in one place can suddenly affect a totally different project, that wasn’t even aware of the other problem.

The ability to update every caller in one commit may also reduce the incentive to design stable, well-considered APIs. Why worry about compatibility if a tool can rewrite all users?

Because architectural coupling still has a price, even when the compiler helps us pay it.

Code Health Is Part of the Infrastructure

A monorepo must actively defend its dependency structure.

Useful safeguards include:

  • making internal APIs private by default,
  • requiring APIs to be explicitly exposed for wider use,
  • marking APIs as deprecated and tracking their remaining consumers,
  • detecting unused dependencies and dead code,
  • preventing unwanted dependency directions and cycles, and
  • supporting repository-wide cleanups and refactorings.

These mechanisms should be introduced early. Retrofitting dependency hygiene after the repository has become enormous is like adding the plumbing after building the house. It can be done, but the residents will not enjoy it.

Code health is not a cleanup activity reserved for the week before Christmas. It is part of the infrastructure required to operate a monorepo.

Is a Monorepo the Right Choice?

A monorepo is a strong option when projects share substantial code, and that code changes frequently cross project boundaries. It is essential that collaboration is part of the engineering culture, and that you are willing to invest in builds, tests and repository tooling.

Multiple repositories may be the better choice when projects require strict access isolation, use fundamentally different toolchains, are maintained by independent organizations or rarely change together.

The size of the company is not the deciding factor. A small company can benefit from a monorepo because it avoids release overhead. A large company can fail with one because it underestimates the necessary tooling and governance.

Do not choose a monorepo because Google uses one. Choose it if you want to solve the same class of coordination problems and are prepared to accept the costs of solving them centrally.

Summary

A monorepo offers one source of truth, simpler code sharing, atomic changes and powerful large-scale refactoring. It can improve collaboration and make dependencies visible across an entire organization.

It also creates a large blast radius. Git operations and pipelines may become slow, the main branch affects everyone and adding ill-considered dependencies becomes dangerously easy.

A monorepo does not remove complexity. It moves complexity from versioning and cross-repository coordination into tooling, dependency hygiene and engineering culture.

That brings me to my key question: Would I do it again, and consolidate my entire business into a single mono-repository? The answer is still “Yes” and “But”. The “Yes” refers to the fact that I have a single place to go to, and the ability to directly cross-reference everything in one place. These days the use of coding agents make this point even more compelling. The downside is significantly more complexity during builds since I still haven’t solved my toolchain problem — parts of the repository use Python, others use node. Some import dependencies via nix, others simply assume they are available in the current environment.

So next time I’d rather spend a bit more time upfront standardizing the toolchain, rather than ending up with a huge amalgam of different environments.

Further Reading