Monorepo vs Microrepo: How to Choose the Best Repository Structure for Your Code
Tags: git, developer, beginners, softwareengineering
Published: 2023-08-13 01:27:07

In this article, we’ll look at What is Monorepo and Microrepo? What are their advantages and disadvantages?

When we work on software development, we need to decide how to organize our code in version control repositories. There are two main strategies for storing code: Monorepo and Microrepo.

## Monorepo: One Big Repository for All Our Code

A Monorepo is a single repository that contains all the code for different parts of our software system. For example, we might have one repository that has the code for our front-end, back-end, testing, etc… Here are some companies using Monorepo: [Google](https://cacm.acm.org/magazines/2016/7/204032-why-google-stores-billions-of-lines-of-code-in-a-single-repository/fulltext), [Facebook](https://www.facebook.com/atscaleevents/videos/systems-scale-2019-monorepos-moving-fast-in-a-huge-repository/457153524992062/), [Microsoft](https://devblogs.microsoft.com/bharry/the-largest-git-repo-on-the-planet/), etc…

### Why Use a Monorepo?👍

* **Easy Code Sharing**: We can use the same code and libraries in different projects, which can save time and make our code more consistent.

* **Simple Dependency Management**: We only need to manage one set of dependencies for our whole system, which can avoid version conflicts and ensure compatibility.

* **Easy Refactoring**: We can make changes to multiple parts of our system in one place, which can make refactoring easier and faster.

* **Uniform Tooling**: We can use the same tools and processes for our entire codebase, which can make our development practices and workflows more standard.

### Why Not Use a Monorepo?👎

* **Complexity**: It can become very large and complex as our system grows, and it might be hard to find and understand the code we need.

* **Long Build and Test Time**: It can take a long time to build and test, which can slow down our development speed.

* **Risk of Coupling**: A change in one part of our system might affect other parts that we didn’t intend to, which can cause bugs and dependencies.

## Microrepo: One Small Repository for Each Part of Our Code

A Microrepo is a separate repository for each part of our software system. For example, we might have one repository for each service, component, or project. Here are some companies using Microrepo: [Netflix](https://netflixtechblog.com/towards-true-continuous-integration-distributed-repositories-and-dependencies-2a2e3108c051), Amazon, Spotify, etc...

### Why Use a Microrepo?👍

* **Isolation**: Each repository is independent, which can reduce the chance of unwanted interactions between parts of our system.

* **Scalability**: Microrepos can scale more easily since each repository has its own build and test times.

* **Autonomy**: Different teams can have more control over their own codebases, which can make it easier to make decisions and iterate quickly.

* **Clear Ownership**: Each repository has a clear owner, which can make it easier to assign responsibility and accountability.

### Why Not Use a Microrepo?👎

* **Code Duplication**: We might have to repeat some code and libraries in different repositories, which can make maintenance harder.

* **Dependency Management Complexity**: We have to manage dependencies across multiple repositories, which can be tricky and require careful version tracking.

* **Cross-Project Refactoring**: We might have to coordinate and work harder to make changes that involve multiple projects.

Here is a summarized table of advantages and disadvantages
{% gist https://gist.github.com/kananinirav/1fa3923e8e9a67c9f3d1ae2820929973.js %}

![source](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p8hfminqj5vcdcn84n3j.jpg)

## How to Choose Between Monorepo and Microrepo?

There is no right or wrong answer when it comes to choosing between Monorepo and Microrepo. It depends on many factors such as the size of your organization, the complexity of your projects, and your development preferences. Some organizations even use a mix of both approaches. You should think about your team’s needs, development processes, and the specific problems you want to solve before deciding on a Monorepo or Microrepo approach.

### Reference

* [Why Google and Meta Put Billion Lines of Code In 1 Repository? — YouTube](https://www.youtube.com/watch?v=x3cANGNPyx0)

* [Why Does Google Use Monorepo?](https://blog.bytebytego.com/p/ep62-why-does-google-use-monorepo)

If You are using [Medium](https://medium.com/) Please support and follow me for interesting articles. **[Medium Profile](https://medium.com/@kanani-nirav)**

**Stay updated with my latest and most interesting articles by following me.**

**If this guide has been helpful to you and your team please share it with others!**