What is a monorepo vs a polyrepo, and how does it affect CI/CD?
BeginnerConceptCI/CD practices
Answer
In one line: A monorepo keeps many projects or services in one Git repository; a polyrepo gives each project its own repository — and each choice changes how you build pipelines.
Monorepo
- Pros: one place for all code, easy to change several services in one PR, shared tools and standards, easy code reuse.
- Cons: the repo can get huge; CI must avoid building everything for every change; access control is coarser.
- CI/CD needs: path-based triggers or build tools that detect affected projects (Nx, Turborepo, Bazel, Pants), caching, and per-service deploy jobs.
Polyrepo
- Pros: clear ownership, independent pipelines and versioning, smaller repos, fine-grained access.
- Cons: changes across services need several PRs; versions of shared libraries drift; duplicated pipeline code.
- CI/CD needs: reusable pipeline templates so 50 repos don't have 50 slightly different pipelines; dependency update bots.
| Monorepo | Polyrepo | |
|---|---|---|
| Cross-service changes | One PR | Many PRs |
| Pipeline triggers | Path filters / affected detection | Simple, one per repo |
| Ownership | Via CODEOWNERS | Via repo permissions |
| Examples | Google, Meta, many startups | Many microservice organisations |
Example — monorepo path filter (GitHub Actions):
on:
push:
paths: ["services/payments/**", "libs/common/**"]
Only the payments pipeline runs when payments code (or its shared library) changes.
Tip for interviews: there's no single right answer. Explain the trade-offs and the CI techniques each one needs.
More on CI/CD practices
What is "pipeline as code", and why is it better than configuring pipelines in a UI?BeginnerWhat is a build agent or runner?BeginnerWhat are pipeline triggers?BeginnerWhat is a quality gate in a CI/CD pipeline?BeginnerHow do you make a slow CI/CD pipeline faster?BeginnerWhat are secrets in CI/CD, and how should they be handled?Beginner