Video in progress

How does the choice between a monorepo and a polyrepo affect coupling between modules?

A monorepo makes atomic changes easy (you can change an API and all its consumers in one PR), but for exactly that reason boundaries erode. A polyrepo enforces boundaries, but versioning and coordination cost a lot. Coupling is controlled by extra rules, not by the repo.

📖 Answer

What happens in a monorepo:

  • anyone can import any module's internal class. "Temporary" imports pile up, and the modules effectively turn into one big module;
  • the upside: you can change an API and update all callers in one commit: no deprecation cycles needed, refactoring is cheap;
  • one build system, one set of dependency versions: no "diamond dependency" problem.

In a polyrepo:

  • dependency goes only through a published artifact: internal classes are out of reach;
  • but every change means a library release, then bumping the version in every consumer. Many services stay on old versions, and you end up supporting 5 versions at once;
  • there is no "atomic" refactoring, so APIs freeze and never change: sometimes that's good, sometimes bad.

How I decide:

  • modules working on one product that often change together: a monorepo, but with the boundaries enforced by technical tools: Gradle/Maven modules (depend only on the api module), ArchUnit, CODEOWNERS (the module owner must approve the PR);
  • platform libraries with an independent lifecycle, used by other organizations or many teams: a separate repo and semver.

The catch is that a polyrepo doesn't reduce coupling, it just makes it more expensive. If services have to be deployed together on every release, they are a distributed monolith even when they sit in separate repos. First look at the dependency graph (who calls whom, which changes come together: a "change coupling" analysis from git history), and then fit the repo structure to that.