Dev tools
Monorepo vs Polyrepo: Which Fits Your Team?
Monorepo vs polyrepo compared: code sharing, atomic changes, CI, versioning, ownership, tooling (Nx, Turborepo, Bazel) and how to choose for your team.
In monorepo vs polyrepo, the question is simple: do you keep all your projects in one version-control repository or give each project its own? A monorepo holds many services, libraries and apps side by side, sharing one history and one set of tooling. A polyrepo setup (also called multi-repo) splits them into separate repositories, each with its own history, versioning and release process.
Neither is better in general. A monorepo makes sharing code and changing many projects at once easy, at the cost of needing smarter build and CI tooling as it grows. Polyrepos give teams independence and simple, small repositories, at the cost of coordinating changes across many repos and managing versions of shared libraries. Google famously keeps most of its code in one giant repository; many other successful companies run hundreds of separate repos. This guide explains the trade-offs, what tooling each needs, how CI changes, a worked example and how to choose.
Monorepo vs Polyrepo at a Glance
| Monorepo | Polyrepo | |
|---|---|---|
| Structure | Many projects in one repository | One repository per project or service |
| Code sharing | Import directly from shared folders | Publish shared code as versioned packages |
| Cross-project changes | One atomic commit and pull request | Coordinated pull requests across repos, in order |
| Versioning | Often everything at the latest version ("one version") | Each repo versions and releases independently |
| CI | Needs "affected only" builds and caching to stay fast | Simple per-repo pipelines |
| Ownership | Shared repo; ownership by folder (CODEOWNERS) | Clear per-repo ownership and permissions |
| Discoverability | All code searchable in one place | Needs cross-repo search tools |
| Tooling needs | Workspace and build tools (Nx, Turborepo, Bazel and others) | Package registry, dependency update automation |
| Scaling pain | Repo size, clone time, CI time | Dependency drift, coordination overhead |
What Is a Monorepo?
What is a monorepo? It's a single repository containing multiple distinct projects that could, in principle, live on their own. It's not the same as a monolith: a monorepo can hold dozens of independently deployed microservices. The "mono" refers to the repository, not the architecture.
A typical JavaScript or TypeScript monorepo looks like this:
repo/
apps/
web/ # customer-facing site
admin/ # internal dashboard
api/ # backend service
packages/
ui/ # shared design system
auth/ # shared auth helpers
config/ # shared lint and TypeScript settings
package.json # workspace definition
turbo.json # or nx.json: build pipeline and cachingThe biggest public example is Google. In a 2016 paper in Communications of the ACM, Rachel Potvin and Josh Levenberg described Google's repository as holding about 86 TB of data, including roughly two billion lines of code in nine million unique source files as of January 2015, used by about 95% of its software developers. Google built its own version-control system, Piper, to handle that scale.
Monorepo vs Multirepo: The Trade-offs
The monorepo vs multi repo choice comes down to where you want the friction.
Changing shared code
In a monorepo, changing a shared library and every project that uses it happens in one pull request: one review, one CI run, one atomic merge. In a polyrepo setup, you change the library, publish a new version, then update each consuming repo, often over days or weeks, with some projects lagging behind.
Versions and dependencies
Monorepos often follow a single-version policy: all projects use the same version of each third-party dependency. That prevents conflicts but forces everyone to upgrade together. Polyrepos let each project upgrade on its own schedule, which is flexible but leads to version drift, where different services run very different versions of the same library and security patches spread slowly.
Independence and ownership
Polyrepos make boundaries obvious: separate permissions, separate pipelines, separate release cadences. In a monorepo, teams share one repository, so ownership is enforced by folder with tools such as a CODEOWNERS file, and a broken shared build can block everyone until it's fixed.
Discoverability and consistency
In a monorepo, anyone can search all the code, see who calls a function and fix a bug everywhere at once. Shared lint, formatting and build settings keep projects consistent. With polyrepos, every repo tends to drift into its own conventions unless a platform team maintains templates.
Monorepo Pros and Cons
Here are the monorepo vs polyrepo pros and cons side by side.
| Monorepo pros | Monorepo cons |
|---|---|
| Atomic changes across projects | CI must be smart, or every change rebuilds everything |
| Easy code sharing without publishing packages | Repository can grow large; clones and checkouts get slower |
| One set of tooling, lint and build rules | One broken main branch affects everyone |
| Whole-codebase search and refactoring | Permissions are coarser than separate repos |
| Single source of truth for dependency versions | Upgrades must happen everywhere at once |
| Polyrepo pros | Polyrepo cons |
|---|---|
| Small, fast repositories | Cross-repo changes need coordination and version bumps |
| Clear ownership and fine-grained access | Version drift and duplicated code |
| Independent pipelines and release cadence | Harder to discover code across repos |
| Simple tooling per repo | Inconsistent conventions without a platform team |
| Failures stay contained | Integration problems surface late |
Security and Dependencies
Repository layout changes how you manage risk:
- Dependency inventory. A monorepo with a single-version policy has one list of third-party packages to scan and patch. With polyrepos, the same library may appear in dozens of repositories at different versions, each needing its own update.
- Patching speed. Fixing a vulnerable dependency in a monorepo is one change, tested against everything at once. In polyrepos, the fix rolls out repo by repo, and the slowest team sets the exposure window.
- Access control. Polyrepos make it simple to restrict who can read sensitive code. Monorepos rely on branch protection and review rules by folder, and everyone with access can usually read everything.
- Secrets. A secret committed anywhere in a monorepo is visible to everyone who can clone it, so secret scanning on every commit matters even more.
Day-to-Day Developer Experience
| Task | Monorepo | Polyrepo |
|---|---|---|
| New developer setup | One clone, one install, one set of scripts | Clone each repo you need; setups may differ |
| Running the whole system locally | Often one command from the root | Coordinate versions and start each service separately |
| Finding how something is used | Search the repository | Search across repositories with extra tooling |
| Reviewing a cross-cutting change | One pull request shows the full picture | Several pull requests reviewed separately |
| Release notes and versioning | Needs tooling to version packages separately, if required | Natural per repository |
Monorepo Tools
Monorepo tools exist mainly to answer one question quickly: what changed, and what depends on it?
| Tool | Ecosystem | Strengths |
|---|---|---|
| Nx | JavaScript/TypeScript, with plugins for other languages | Project graph, affected commands, local and remote caching, code generators |
| Turborepo | JavaScript/TypeScript | Simple task pipelines with caching; easy to adopt |
| Bazel | Multi-language (open-sourced by Google) | Hermetic, reproducible builds at very large scale; steeper learning curve |
| Pants | Python, Go, Java and others | Fine-grained dependency inference and caching |
| Rush | JavaScript/TypeScript | Large Node.js monorepos with strict dependency policies |
| Package manager workspaces | npm, pnpm, Yarn, Cargo, Go workspaces | Linking local packages without extra tools |
Git itself has improved for large repositories: sparse checkout lets developers check out only the folders they need, and partial clone avoids downloading every historical file version upfront. Our guide to git worktree covers another way to work on several branches of a large repository at once.
Polyrepos need different tools: a private package registry for shared libraries, automated dependency updates to fight drift, cross-repo code search, and repository templates so new services start consistent.
CI in a Monorepo: A Worked Example
The classic monorepo failure is CI that rebuilds and tests everything on every commit. With 40 packages and an average of 3 minutes to build and test each, a full run takes 120 minutes of compute.
With affected-only builds, the tool walks the dependency graph. A change to the shared auth package affects auth itself plus the five projects that import it, so CI builds and tests 6 packages: 18 minutes, 85% less. Add a remote cache, and anything already built with identical inputs, on CI or on a teammate's machine, is downloaded instead of rebuilt.
| CI approach | Packages built | Compute time |
|---|---|---|
| Build everything | 40 | 120 minutes |
| Affected only | 6 | 18 minutes |
| Affected plus remote cache hits on 3 unchanged dependencies | 3 | 9 minutes |
The figures are illustrative, but the pattern is why monorepos are practical at scale: without a dependency graph and caching, they slow down as they grow; with them, CI cost tracks the size of the change, not the size of the repository.
Monorepo vs Polyrepo: How to Choose
| Situation | Leans towards | Why |
|---|---|---|
| Startup or small team with a few related apps | Monorepo | Easy sharing, one setup, fast cross-cutting changes |
| Front end, back end and shared types in TypeScript | Monorepo | Shared code and types without publishing packages |
| Many independent teams with separate products | Polyrepo, or several monorepos | Autonomy and clear boundaries |
| Open-source libraries consumed by outsiders | Polyrepo per library (often) | Independent versions and contributor access |
| Strict access control between codebases (contractors, regulated code) | Polyrepo | Repository-level permissions |
| Large organisation with a strong platform team | Either; tooling decides | Both scale with investment |
Team size alone isn't decisive. A ten-person team with five unrelated products may be happier with separate repositories, while a thousand-person company with shared platform code may thrive in a monorepo. Look at how often changes cross project boundaries: the more they do, the more a monorepo pays off. Many organisations land in between: a handful of monorepos, one per product area or team, rather than one giant repo or hundreds of tiny ones. Whatever you choose, record the decision and its reasons; an architecture decision record is a good format.
Migrating Between Models
- Polyrepo to monorepo: move repositories in one at a time, keeping history with
git subtreeor history-preserving import tools; introduce workspace tooling and affected builds before CI times climb. - Monorepo to polyrepo: extract a project with its history using tools such as
git filter-repo, publish shared code as packages, and set up separate pipelines.
Either way, migrations touch every developer's workflow. Plan them in stages, and consider how you'll integrate changes, such as rebasing or merging, in the new layout; our comparison of git rebase vs merge covers that choice.
Common Mistakes
- A monorepo without build tooling, so CI time grows with every new project.
- A polyrepo without dependency automation, so services drift years apart.
- Confusing monorepo with monolith.
- No ownership rules in a shared repository.
- Splitting too early, creating many tiny repos for a small team.
- Moving everything at once during a migration.
FAQ
Is a monorepo the same as a monolith?
No. A monolith is one deployable application. A monorepo is one repository that can contain many independently deployed applications and services.
Do big companies use monorepos?
Some do, most famously Google, which described its single repository in a 2016 paper. Many others use many repositories, or a mix of both.
Are monorepos slow with Git?
Very large ones can be. Sparse checkout, partial clone and build tools with caching keep most monorepos fast; only the very largest need custom version-control systems.
Which is better for microservices?
On monorepo vs polyrepo for microservices, either works. A monorepo makes shared code and coordinated changes easier; a polyrepo gives each service more independence.
What is a polyrepo?
A setup where each project, service or library lives in its own repository, with its own history, versioning and pipeline.