Video in progress

Staff 🌿 Git

For internal libraries in a monorepo, how do you choose between a "single version" policy and independent versioning?

Under a single-version policy, every service uses the library as it is on main: there is no "dependency hell", but whoever introduces a breaking change has to fix every service that uses the library. Independent versioning gives teams freedom, but loses the monorepo's main advantage.

📖 Answer

Single version (the Google style):

  • if libs/money changes, everything that uses it is updated in the same PR, and CI tests them;
  • external dependencies are also one: a single BOM or libs.versions.toml for the whole repo;
  • a security update is one PR, and every service updates at the same time.

The cost: the library owner has to touch the code of 30 services, which needs good refactoring tools (the IDE, OpenRewrite recipes) and trust with the consumer teams. Big changes still have to be done in stages: add the new API, migrate consumers, mark the old one @Deprecated(forRemoval = true), then remove it.

Independent versioning inside a monorepo:

  • each library is published with its own version, and services pin an exact version;
  • teams upgrade at their own pace;
  • but now the monorepo is really a polyrepo in one Git repo: no atomic changes and no single state, while you carry the complexity of both.

I usually pick a single version for internal code, and separate versioning with SemVer for things published to the outside world (a public SDK, a client that other companies use). An exception: if one service is stuck on an old technology stack (still on Spring Boot 2.x, say), it can be isolated temporarily with its own version, but with a migration date.