Monorepo vs Polyrepo
Choosing whether to keep multiple projects or packages in one shared repository or in separate ones, and the tradeoffs of each.
What is it?
Once a system grows past one app (say, a web frontend, a backend API, and a couple of shared libraries), you face a structural question that has nothing to do with classes or layers: how many git repositories should it all live in?
Put every app and shared package into one repository and you have a monorepo:
- A change to both the frontend and a shared library is one commit and one pull request. - Every project always sees the latest version of every shared package, since there's only one copy. - But the repo grows large, build systems and CI must be taught to handle many projects efficiently, and teams can more easily step on each other's code.
Give each project its own repository and you have a polyrepo:
- Each team gets a clean, independently versioned space with clear ownership. Unrelated changes never show up in your history. - But sharing code means publishing and versioning packages instead of importing a local file. - A change across repos means coordinating several pull requests, reviews, and release timings, which is much more overhead.
Neither is universally "correct". Large companies succeed with both, and some run a mix.
Explain like I'm 10
A monorepo is one big shared office building: easy to walk over and coordinate, but you need clear floor plans (tooling) so teams don't clutter each other's space. A polyrepo is a separate building per team: cleaner boundaries, but meetings between buildings take more coordination.
Examples
Polyrepo: sharing code requires publishing a package
// In repo "shared-utils" (its own repository, its own version)
// package.json: { "name": "@acme/shared-utils", "version": "1.4.0" }
export function formatCurrency(cents) { /* ... */ }
// In repo "web-app" (a separate repository)
// package.json: "dependencies": { "@acme/shared-utils": "^1.4.0" }
import { formatCurrency } from "@acme/shared-utils";
// To pick up a bugfix in formatCurrency, web-app must bump its
// dependency version and go through its own release process.A formatCurrency fix must be released as a new package version before web-app can use it: two steps, two repos, two reviews.
Monorepo: sharing code is a direct import
// One repository, multiple folders
// packages/shared-utils/formatCurrency.js
export function formatCurrency(cents) { /* ... */ }
// apps/web-app/checkout.js
import { formatCurrency } from "../../packages/shared-utils/formatCurrency";
// A fix to formatCurrency is visible to web-app immediately,
// in the very same pull request if needed.The fix and its usage are reviewed and merged together, atomically, with no separate release step. The cost: both projects now live in one shared repository, built by shared tooling.
How it works
The key difference is how code crosses a project boundary.
In a polyrepo, it always goes through a published, versioned package. That adds process, but also a deliberate checkpoint: you choose when to upgrade.
In a monorepo, it's just an import. There's no checkpoint (everyone is always on the latest version), and you need tooling that works out which parts of a huge repo to rebuild or retest for each change, since rebuilding everything on every commit doesn't scale.
Why does it exist?
It's an open tradeoff, not a solved problem. The two costs (coordination across repos vs. tooling and organizational overhead in one giant repo) both grow with organization size, but in opposite directions.
Small, tightly coordinated teams feel the coordination cost more. Large organizations with many independent teams feel the "everyone in one giant repo" cost more. That's why both models succeed at scale.
When to use it
A monorepo fits when projects share a lot of code and evolve together, you want atomic changes across projects, and you'll invest in tooling to keep builds and tests fast as it grows. It also avoids polyrepo drift over "which version of the shared library is everyone on".
When not to use it
A polyrepo fits better when:
- Projects are truly independent (different release cycles, teams with little overlap, or even other companies or open-source consumers). - A monorepo's shared tooling and access would add coordination cost with no matching benefit. - You want strict, deliberate version boundaries between components.
Common mistakes
Adopting a monorepo without investing in tooling (like build caching or affected-project detection), so CI gets painfully slow as it grows.
Using a polyrepo for tightly coupled projects that always change together, causing a stream of synchronized multi-repo pull requests for nearly every feature.
Treating the choice as permanent instead of revisiting it as the number of teams, projects, and shared code changes.
Practice exercises
- Easy:
In your own words, list two concrete costs and two concrete benefits of a monorepo, and the same for a polyrepo, based on the explanation above.
- Medium:
One small team builds a web frontend, a mobile app, and a shared design-system package both use. Argue whether a monorepo or polyrepo fits better, and why.
- Hard:
Describe a tooling problem a very large monorepo (thousands of projects) must solve that a small one doesn't, and outline one high-level strategy for solving it.
Interview questions
What is the core tradeoff between a monorepo and a polyrepo?
A monorepo makes cross-project changes atomic and keeps everyone on the same version of shared code, but needs tooling to scale and clearer internal boundaries. A polyrepo gives each project a clean, independently versioned and owned space, but needs package publishing and multi-repo coordination for shared changes.
Why does a monorepo need special build tooling as it grows?
Rebuilding and retesting every project on every commit doesn't scale. Tooling must work out which projects a change actually affects and only rebuild and retest those.
In a polyrepo setup, how does one project pick up a bugfix made in a shared library?
The library publishes a new package version. The consuming project then updates its dependency and goes through its own release process. It's not automatic like a local import.