The World City, The Builder's Choice
Monorepo vs polyrepo, the strategic decision
At the end of a road crossing three kingdoms stands the World City, a metropolis so vast it has its own seasons. Thousands of craftspeople work in the same interconnected workshop: smiths, weavers, alchemists, scribes, all under the same titanic roof.
The City Architect greets you atop the central tower. From there, you can see the immensity of the workshop below.
Β« Before descending into the technical arcana of the City, you must understand why some kingdoms chose this model and others did not. It is a strategic decision, not just a technical one. Let me show you both paths, and the price of each. Β»
Monorepo vs Polyrepo
When a team or company manages multiple projects, two approaches stand opposed:
Polyrepo - one repository per project
This is the most common approach. Each project, service or library has its own Git repository.
# Polyrepo - each project is a separate repository
github.com/my-team/frontend # React application
github.com/my-team/backend-api # Node.js API
github.com/my-team/auth-service # Authentication service
github.com/my-team/shared-utils # Shared library
github.com/my-team/mobile-app # Mobile application
github.com/my-team/infra # Terraform configuration Advantages:
- Each project is independent - its own history, its own branches, its own CI
- Fine-grained permissions: you can grant access to one repository without granting access to the others
- Fast clones: each repository is lightweight
- Simplicity: no special tooling needed
- Autonomous teams: each team manages its repository as it sees fit
Disadvantages:
- Code sharing is difficult: the shared library must be published as a package, with its own version
- Cross-cutting refactoring is painful: changing an API impacts multiple repos = multiple PRs, multiple reviews, multiple deployments
- Inconsistencies: each repository can use different versions of tools, linters, frameworks
- Dependency hell: managing versions between interdependent repositories
Monorepo - everything in a single repository
The monorepo approach puts all the code from the organization into a single giant Git repository.
# Monorepo - everything in a single repository
github.com/my-team/platform/
βββ apps/
β βββ frontend/ # React application
β βββ backend-api/ # Node.js API
β βββ mobile-app/ # Mobile application
β βββ auth-service/ # Authentication service
βββ packages/
β βββ shared-utils/ # Shared library
β βββ ui-components/ # Shared UI components
β βββ config/ # Shared configuration (ESLint, TS, etc.)
βββ infra/ # Terraform configuration
βββ docs/ # Centralized documentation Advantages:
- Trivial code sharing: importing a shared package = a simple import, no version publishing
- Atomic refactoring: change a shared API + all its consumers in a single commit
- Consistency: one version of tools, one configuration, one standard
- Visibility: everyone sees all the code (transparency)
- Simple integration tests: everything is there, no need to mock other services
Disadvantages:
- Size: the repository can become enormous (GB of history)
- Tooling required: Git alone isn't enough, you need specialized tools
- Complex CI/CD: building and testing everything on each commit would be too slow
- Permissions: everyone sees everything (can be a disadvantage in some contexts)
- Training: the team must learn new tools
Who uses what?
| Company | Approach | Details |
|---|---|---|
| Monorepo | A single repo for nearly all code (billions of lines). In-house tool: Piper/CitC | |
| Meta (Facebook) | Monorepo | A massive Mercurial monorepo for the main codebase |
| Microsoft | Mix | Windows is in a giant monorepo (VFS for Git). Other projects in polyrepo |
| Twitter/X | Monorepo | A monorepo with Pants as build tool |
| Netflix | Polyrepo | Hundreds of microservices, each with its own repo |
| Amazon | Polyrepo | "Two-pizza teams" philosophy with independent services |
| Vercel | Monorepo | Uses Turborepo (which they created) |
The Architect pauses. Β« Now that you know both approaches, let us talk about the cost. A monorepo is not free. It demands tooling, discipline, and trade-offs that not everyone is willing to accept. Β»
The cost of a monorepo
A monorepo isn't free. Before diving in, make sure you understand what it entails:
Tooling
You'll need to set up and maintain tools like Nx, Turborepo or Bazel. These tools have their own learning curves and their own bugs. Someone on the team will need to become the expert.
Training
All developers need to understand the new workflows. "Why doesn't my build run everything?" "How do I target a single project?" "Why is the cache giving me an old result?" Plan time for training.
More complex CI
CI needs to be smarter. Instead of a simple "npm test", you need to implement affected detection, distributed cache, and parallelization. CI pipelines are more complex to write and debug.
Git under pressure
Git wasn't designed for repositories of several GB. You'll need to use partial clone, sparse checkout, and potentially git maintenance to keep performance acceptable.
# Enable automatic Git maintenance
# (optimizes pack files, updates indexes, etc.)
git maintenance start
# This launches background tasks:
# - gc: orphaned object cleanup
# - commit-graph: speed up history traversal
# - prefetch: pre-fetch objects from the remote
# - loose-objects: consolidate loose objects
# - incremental-repack: incremental pack file repacking When to choose a monorepo?
- Your projects share a lot of code between them
- You regularly do cross-cutting refactorings
- You want to enforce uniform standards (linter, formatter, conventions)
- You have the resources to invest in tooling
- Your team is ready to learn new tools
When to stay with polyrepo?
- Your projects are very independent from each other
- You have autonomous teams with different technologies
- Simplicity is your priority
- You don't have the resources to invest in monorepo tooling
- Access permissions to code must be strictly separated
"You see the World City down there? It's magnificent. But it wasn't built in a day. It took architects, roads, supply systems, cohabitation rules. A monorepo without tooling is a city without roads - total chaos. If you choose this path, invest in the foundations."
Β« You now know the strategic choice and its price. If you decide the World City is the right path for your kingdom, you still need to master its technical arcana: how Git and its tooling handle a workshop of this size in practice. Β»
Next step: A3b, The City Arcana.