Polyrepo: mỗi service/app có repo riêng. Branching đơn giản hơn, CI riêng biệt, team độc lập. Nhược điểm: cross-repo changes phức tạp (cần coordinate nhiều PRs), version hell khi shared library update, hard để làm atomic change spanning nhiều services.
Monorepo: tất cả code trong 1 repo. Atomic changes, single source of truth cho shared code, dễ refactor cross-cutting concerns. Nhược điểm: CI chậm hơn, cần tooling (Nx, Turborepo), git clone lớn.
Git workflow differences:
- Polyrepo: mỗi repo có branch protection, deploy pipeline riêng
- Monorepo: cần scoped CI (nx affected), CODEOWNERS phân quyền theo path, tag versioning phức tạp hơn
Khi nên migrate sang Monorepo: thường xuyên cần thay đổi shared library và update consumers đồng thời, khó maintain consistency (linting, tsconfig, deps) across repos, cross-repo PR coordination tốn >2 giờ/sprint.
Migration: không phải "big bang" — dùng git subtree để import history, giữ polyrepo cũ read-only.
Polyrepo: each service/app has its own repo. Simpler branching, isolated CI, independent teams. Downsides: cross-repo changes are complex (need to coordinate multiple PRs), version hell when shared libraries update, hard to make atomic changes spanning multiple services.
Monorepo: all code in one repo. Atomic changes, single source of truth for shared code, easy cross-cutting refactors. Downsides: slower CI, requires tooling (Nx, Turborepo), larger git clone.
Git workflow differences:
- Polyrepo: each repo has its own branch protection and deploy pipeline
- Monorepo: needs scoped CI (nx affected), CODEOWNERS for path-based permissions, more complex tag versioning
When to migrate to Monorepo: frequent need to change shared libraries and update consumers simultaneously, hard to maintain consistency (linting, tsconfig, deps) across repos, cross-repo PR coordination costs >2 hours per sprint.
Migration: not a "big bang" — use git subtree to import history, keep old polyrepos read-only.