Video in progress

Staff 🌿 Git

For a company with 40 Java microservices, how do you decide between a monorepo and a polyrepo?

This is not a Git decision, it is an organizational one: a monorepo gives atomic changes and a single version policy, but requires a big investment in the build system and tooling. A polyrepo gives teams independence, but cross-service changes and dependency versions become scattered.

📖 Answer

I start the debate not with "which is better" but with "which pain can we carry".

What a monorepo gives:

  • changing several services and a shared library in one PR, with an API change and all consumers together;
  • one spring-boot / Jackson version for the whole company, and fewer "diamond dependency" problems;
  • refactoring and code search across all the code;
  • one CI configuration, one set of rules.

The cost:

  • you have to build/test only the changed part, otherwise every PR builds 40 services. You need Gradle's build cache and configuration cache, or a tool like Bazel;
  • Git size: sparse-checkout, partial clone, fsmonitor;
  • ownership: CODEOWNERS and branch protection need finer setup;
  • a bug in one shared library breaks everyone at the same time.

In a polyrepo it is the other way around: each team goes at its own speed, with its own releases, but 7 different versions of common-lib live in prod, and getting a security fix to 40 repos becomes a project of its own.

My usual recommendation: if there is no platform team (build, CI, developer tooling), a polyrepo, but with Renovate/Dependabot, a shared BOM and a template repo. If there is a platform team and the services are strongly coupled, a monorepo. There is a middle way too: several "small monorepos" by domain. Before deciding, count how many changes in the last 3 months touched several repos. That is the best signal.