Video in progress
How does moving to a monorepo affect CI/CD, and how do you keep build time under control in a Java monorepo with 100 modules?
A monorepo gives atomic changes and single versions, but if you build everything on every commit, CI dies. You need to build only the changed module and what depends on it, use a remote build cache, and deploy each service separately.
📖 Answer
The benefit is real: you change a shared library and update the 30 services that use it in one PR, with no version hell. But for CI it is heavy.
What helps:
Affected-only builds: from the changed files, find the dependent modules using the module graph. Gradle does this well with the build cache and configuration cache. In Maven, -pl <module> -amd (also-make-dependents) is the basis, but you write the changed-module detection yourself. Bazel or Gradle Develocity are more precise on a large repo.
Remote build cache: the result of a module compiled/tested once in CI is reused in other builds. Tasks must be deterministic: writing the build time into the jar breaks the cache.
Test selection and splitting: split tests across runners (sharding), and move slow integration tests to a separate stage.
Independent deploys: a monorepo does not mean a monolith deploy. Each service has its own image, and only the service whose image digest changed gets deployed. Otherwise one line in a shared utils redeploys 100 services.
The organizational side:
- CODEOWNERS: every folder has an owner, and review is mandatory;
- a change to a shared library affects many teams, so it gets stricter review and more tests;
- if trunk is red, everyone stops: a merge queue and a rule of "whoever broke it fixes it or reverts".
What to measure: p50/p90 CI time for PRs, cache hit rate, the number of flaky tests. My threshold: when PR CI goes over 15 minutes, it is time to invest.
Sign up to mark studied questions and save your progress.