Monorepo

Repositorio único

Escrito por Darjus Kazakevic · revisado el

One repository, many projects, and one commit that changes them all.

A monorepo is one repository that holds many projects: services, libraries, apps and infrastructure. They share one commit history and usually one version of each dependency. Google, Meta and Microsoft run very large ones. A four-person team with a pnpm workspace has one too. Size does not define it.

The main benefit is the atomic change. You rename a function in a shared library and fix all 19 callers in one commit, reviewed and tested together. The cost is tooling. Checkout, CI and builds grow with the whole tree, so a large monorepo needs a tool like Nx, Turborepo or Bazel to build and test only what changed.

En esencia — Put many projects in one repository, so a change across them is one atomic commit. Pay for it with build tooling that scales.

Cuándo recurrir a él

Recurre a él cuando

  • Projects change together often: shared libraries, a design system, clients
  • You want one version of each dependency, not a long tail of old ones
  • Refactoring across project boundaries should stay cheap

Reconsidéralo cuando

  • Projects release on independent schedules to different customers
  • Some people must not be allowed to read some of the code
  • Nobody owns build tooling, and CI is already slow at today's size

What makes one work

One commit history
Every project shares one history, so a change set has one order and one ID. This is the main point. Everything else on this list exists to make it affordable.
One version of each dependency (Single-version policy)
Every project builds against the same version of each third-party library. No two projects sit on different major versions, and an upgrade happens once, in one commit.
Affected-target detection
The build tool reads the dependency graph, works out which projects a commit can affect, and tests only those. Without it, every push runs the whole suite.
Ownership inside the tree
One repository does not mean one owner. A CODEOWNERS file maps paths to teams and brings back the review boundary that separate repositories gave you without any setup.

Reglas de diseño

Build and test only what a change affects
Set up affected-target detection and remote caching before CI gets slow, not after. A one-line change should run its own tests and its dependants' tests, not the whole suite.
Keep one version of each dependency
Enforce a single version per third-party library in CI. Once two major versions live side by side, you pay the monorepo's costs and still get the polyrepo's dependency mess.
Write ownership down, path by path
Add a CODEOWNERS file from day one and require owner review on shared code. Without it, every path belongs to everyone, and review goes to whoever is fastest.
Deploy each service on its own
One repository is not one deployable. Give each service its own build target and its own release, so the monorepo can hold fifty independently deployed services.

Errores habituales

  • A folder of unrelated projects with no shared build graph. You get the size but none of the atomic changes.
  • No CODEOWNERS file, so every path is everyone's and review goes to whoever is fastest.
  • Running the full test suite on every commit until CI takes 40 minutes and teams ask to split the repository.
  • Assuming one repository means one deployable, and building a single artifact by accident.