Architecture 2023-08-11

Monorepos Explained: Benefits, Drawbacks, and When to Use Them

Understand what monorepos are, the tooling involved (Nx, Turborepo, Bazel), and the practical trade-offs between monorepos and polyrepos for growing engineering teams.

Read in: ja
Monorepos Explained: Benefits, Drawbacks, and When to Use Them

Overview

This article summarizes monorepos.

What is a Monorepo?

A monorepo is a single repository that manages the code for multiple projects. In contrast, managing multiple repositories is referred to as a polyrepo or multi-repo. While it is one of the management policies for microservices, it is not necessarily predicated on microservices. It is not synonymous with a monolith.

Aspects of Monorepos

I have organized the aspects of operating a monorepo.

Code Autonomy

When operated by multiple teams, code outside a team's jurisdiction can be modified.

On GitHub, management through CODEOWNERS can help establish jurisdictional boundaries. It seems necessary to establish some regulations relying on a tool.

Large Mudball

The complexity of dependencies between codes can lead to a "mudball" effect.

This also seems to require some tool-based solutions. For example, Nx allows the creation of libraries with public APIs and can visualize dependencies in a graph.

Scalability

As the amount of code increases, builds, tests, and deployments may slow down, and issues related to Git management may arise.

For the former, this can be resolved by establishing individually executable CI pipelines and deployment flows. This is within the range of tool-based solutions.

The latter may be a bit more challenging. When clone or pull operations become burdensome, it may be necessary to consider some responses.

Using GVFS, a scalable Git developed by Microsoft, leveraging Git LFS, or reluctantly splitting the repository are options.

Freedom of Technology Choice

There are generally no constraints binding you to specific technologies (such as programming languages).

Since code management is centralized, CI/CD, etc., are assumed to involve managing multiple pipelines, so it does not seem to be a particular concern.

However, if there are languages or environments that the build tools do not support, it may limit the range of technology choices.

Branch Strategy

The compatibility with feature branches is not very good, so it seems desirable to adopt a trunk-based strategy. It would also be good to implement feature toggles.

Other Operational Concerns

On GitHub, attention may need to be paid to the operational policies for Issues and Pull Requests.

Advantages and Disadvantages of Monorepos

Advantages

Disadvantages

Tools for Monorepos

Detailed information is organized at monorepo.tools - Many solutions, for different goals.

I have the impression that Bazel, Nx, and Pants are strong candidates.

Personal Thoughts

References

Tags: Monorepo
Share: 𝕏 Post Facebook Hatena
✏️ View source / Discuss on GitHub
☕ Support

If you enjoy this blog, consider supporting it. Every bit helps keep it running!


Related Articles