Lesson Completion
Back to course

Monorepo vs Multirepo

Intermediate
8 minutes4.8Git

The Hook (The "Byte-Sized" Intro)

Google keeps billions of lines of code in a single monorepo. Netflix runs hundreds of separate repos. Both approaches work — but for different reasons. Monorepos make cross-project changes easy. Multirepos give teams autonomy. Choosing wrong doesn't break things immediately — it creates friction that compounds over months until refactoring becomes unavoidable.

📖 What is Monorepo vs Multirepo?

Two strategies for organizing code repositories: one large repo for multiple projects (monorepo) vs separate repos per project (multirepo).

Conceptual Clarity

Side-by-side comparison:

FactorMonorepoMultirepo
StructureOne repo, many projectsOne repo per project
Cross-project changes✅ Single commit❌ Multiple PRs
CI/CDComplex (selective builds)Simple (per-repo)
Access control🟡 Harder (code owners)✅ Per-repo permissions
Dependency sharing✅ Direct imports❌ Package publishing
ToolingNeeds Nx, Turborepo, BazelStandard Git
Repo sizeCan grow very largeStays small
Team autonomy🟡 Shared conventions✅ Independent choices

Who uses what:

CompanyStrategy
Google, Meta, TwitterMonorepo
Netflix, Amazon, SpotifyMultirepo
Many startupsStart monorepo → split later

Real-Life Analogy

  • Monorepo = One big warehouse with departments for clothing, electronics, and furniture. Easy to move items between departments, but the warehouse needs heavy-duty infrastructure.
  • Multirepo = Separate specialty stores. Each runs independently, but coordinating a sale across all stores requires more effort.

Visual Architecture

flowchart TD MONO["📦 Monorepo"] --> APP["app/"] MONO --> LIB["libs/"] MONO --> API["api/"] MULTI["📦 Repo A<br/>Frontend"] -.->|"npm package"| MULTI2["📦 Repo B<br/>Shared Lib"] MULTI2 -.->|"npm package"| MULTI3["📦 Repo C<br/>API"] style MONO fill:#0f3460,stroke:#53d8fb,color:#53d8fb style MULTI fill:#1a1a2e,stroke:#ffd700,color:#ffd700 style MULTI2 fill:#1a1a2e,stroke:#ffd700,color:#ffd700 style MULTI3 fill:#1a1a2e,stroke:#ffd700,color:#ffd700

Why It Matters

  • Team velocity: Wrong structure creates friction in daily workflows.
  • Scaling: Monorepos need specialized tooling at scale (Nx, Bazel).
  • Onboarding: Monorepos are simpler to onboard (one clone, everything there).
  • Migration: Switching later is expensive — choose thoughtfully upfront.

Code

bash
# ─── Monorepo structure ─── # my-company/ # ├── apps/ # │ ├── web/ # │ └── mobile/ # ├── libs/ # │ ├── shared-ui/ # │ └── utils/ # ├── packages/ # │ └── api-client/ # └── package.json ← Workspace root # ─── Monorepo tooling ─── # Nx: npx create-nx-workspace # Turborepo: npx create-turbo # Bazel: enterprise-scale builds # ─── Multirepo structure ─── # github.com/team/web-app ← Separate repo # github.com/team/mobile-app ← Separate repo # github.com/team/shared-utils ← Published as npm package # github.com/team/api-server ← Separate repo # ─── Selective CI in monorepo ─── # Only build what changed: # git diff --name-only HEAD~1 | grep "^apps/web/" && npm run build:web

Key Takeaways

  • Monorepo: One repo for all projects. Great for cross-project changes and shared code.
  • Multirepo: Separate repos per project. Great for team autonomy and simplicity.
  • Monorepos need specialized tooling (Nx, Turborepo, Bazel) at scale.
  • There's no universally "right" answer — it depends on team size, dependencies, and workflow.

Interview Prep

  • Q: What are the pros and cons of a monorepo? A: Pros: atomic cross-project changes, easy code sharing, single CI/CD pipeline, simpler onboarding. Cons: repo size grows large, needs specialized build tooling, access control is harder, CI must be selective.

  • Q: When would you choose multirepo over monorepo? A: When teams need full autonomy (different tech stacks, release cycles), when projects have no shared code, or when repo size would become unmanageable. Multirepos work well when dependencies are published as packages.

  • Q: How do monorepos handle CI/CD efficiently? A: Using tools like Nx or Turborepo that detect which projects are affected by a change (via dependency graph analysis) and only build/test those projects — not the entire monorepo.

Topics Covered

Repository StrategyArchitecture

Tags

#git#monorepo#multirepo#architecture

Last Updated

2026-02-13