Where's Baldo?

The Pros and Cons of Using a Monorepo

4 min read
MonoreposProgrammingPros & ConsSoftwareWeb Development
Article author: michael
michael
Published:
Cover Image for The Pros and Cons of Using a Monorepo
Photo credit: Markus Spiske

This post contains affiliate links. This means at no extra cost to you, I may earn a commission if you purchase through my links. Please see my website disclaimer for more info.

When it comes to managing code bases, one of the biggest decisions you must make is whether to use a monorepo, or keep your projects in multiple, smaller, separated repositories.

Both approaches have their own advantages and disadvantages, so you need to carefully weigh them when making your decision during the initial phase of a new project.

What is a Monorepo?

Per Wikipedia:

In version-control systems, a monorepo is a software-development strategy in which the code for a number of projects is stored in the same repository.

Or more simply, from Vercel’s Turbo.build site:

A monorepo is a collection of many different apps and packages in a single codebase.

More and more companies have realized the advantages to using monorepos, and big names like Google, Microsoft, and Facebook are among those using them.

The Pros of Using a Monorepo

Easier Dependency Management

With a monorepo, all of your code is in one place. This means that managing dependencies CAN become easier, but that definitely isn’t a guarantee.

You don’t have to worry about coordinating multiple repositories and ensuring that each one has the correct dependencies installed. Instead, you can manage your dependencies at the monorepo level, which simplifies the process and reduces the risk of dependency conflicts.

Improved Code Sharing

Because all of your code is in one place, it’s much easier to share code, like utils and UI, between different parts of your project.

This can be particularly useful if you have a large code base with many different components that need to communicate with each other.

Better Collaboration

A monorepo can also make collaboration between team members much easier.

Since everyone is working from the same code base, it’s easier to see what other team members are working on and avoid conflicts when making changes.

Simplified CI/CD

Continuous integration and continuous development/deployment (CI/CD) can be complex processes, particularly when you’re dealing with multiple repositories.

With a monorepo, you can simplify these processes by creating a single pipeline that runs tests and deploys changes across your entire code base.

Simplified Versioning

Versioning can also be a complex process, especially when you’re dealing with multiple repositories.

With a monorepo, you can simplify versioning by creating a single version number for your entire code base. This makes it easier to keep track of changes and ensure that everyone is working from the same version.

Standardized Tooling & Coding

With a monorepo, you can standardize your tooling and coding practices across your entire code base.

This makes it easier to maintain consistency and avoid conflicts when making changes.

The Cons of Using a Monorepo

Increased Complexity

Managing a monorepo can be more complex than managing multiple smaller repositories. This is especially true if you have a large code base with many different components that need to be kept separate.

According to Wikipedia’s article, “Google’s monorepo … which meets the classification of an ultra-large-scale system … must handle tens of thousands of contributions every day in a repository over 80 terabytes in size”!

Increased Risk

With a monorepo, there is a greater risk of breaking changes affecting multiple parts of your code base.

This means that you need to be very careful when making changes, and you need to ensure that you have robust testing and deployment processes in place.

Increased Build Times

Because a monorepo contains all of your code, it can take longer to build and test changes. This can especially be an issue if you have a large code base with many components.

Incompatibility with Some Tools, Libraries, and Frameworks

Unfortunately, not all tools, libraries, and frameworks are compatible with monorepos, so you may need to make some changes to your code base if you want to use them.

Additionally, some tools, libraries, or frameworks may be compatible with one particular monorepo setup, but not another, and there’s no guarantee that each library you use will be compatible with your monorepo setup.


When Should You Use a Monorepo?

According to howtogeek, “Monorepos generally encapsulate multiple systems … such as an API, website, and mobile app. Not all of the artifacts need to be produced for every change.”

In general, a monorepo is a good choice if you have a large code base with many different components that need to communicate with each other - like for example, an API, an end-user front-end, and an admin area. It can also be a good choice if you have a large team of developers who need to collaborate closely.

However, if you have a smaller code base with relatively few components, or if you have a team that works independently on different parts of the code base, then using multiple repositories may be a better choice.

Conclusion

In conclusion, there are pros and cons to using a monorepo for your code base. While it can simplify dependency management, improve code sharing and collaboration, and simplify CI/CD, it can also increase complexity and risk, and lead to longer build times.

Ultimately, the decision to use a monorepo or multiple repositories will depend on the specific needs of your project and team, along with the specific tools, libraries, and frameworks decide to go with.

Shared hosting with Namecheap!

Until next time,
michael 😀

Share this post:

Comments