When starting a new project, it鈥檚 common to ask what the best or most appropriate strategy is for managing architecture at the code repository level. One of the biggest challenges that makes answering this question difficult is identifying a solution that meets the needs of the present听 yet can still evolve in the future as new scaling, integration and modification needs emerge.
听
The approach that ends up being selected is not, of course, definitive. There is always the opportunity to adjust according to change, whether that change is internal or external.
Nevertheless, just because you have the option to make a change doesn鈥檛 preclude the fact that those changes will inevitably have a cost 鈥 are always present in software engineering, after all. This means it is extremely important to make the right decision early on, since it will ultimately ensure we are prepared for future challenges.
听
I have faced these decisions many times throughout my career. In this article I reflect on some of those moments and what I have learned from them: what might I have done differently? Why was one solution right in one context but not another? First, though, let's start from the basics鈥μ
听
What is a repository?
听
A repository is the place where all the files of a project are stored, organized and maintained. They contain a change history, giving teams transparency and control over different possible versions.
Nowadays, repositories are commonly used with , through providers like , , and . These can store a wide variety of file types.
What is a monorepo?
听
A monorepo is not a . It鈥檚 a software development strategy in which a company's entire codebase is stored in a single repository.
听
What are the benefits and challenges of using a monorepo?
听
When deciding whether to use a monorepo it is important to properly evaluate the many trade-offs they involve. Below I鈥檝e highlighted some of the main benefits and challenges.
听
Benefits
听
Monorepos can help teams to almost instantly start writing clean and maintainable code.
They can help with refactoring solutions and documenting flows so when a new member joins the team it鈥檚 easy for them to integrate into existing practices.
With a monorepo, running automated code tests, whether unit, integration, or end-to-end () is much easier.
If you can select an adequate means of managing your code you can minimize potential chaos in the codebase. A good example of this is using , so each business domain that works on the code can be easily administered.
Because monorepos centralize collaboration, communication within teams should be more effective. Everyone will be clear on the needs and priorities of the team.
Monorepos make it easier to manage dependencies by virtue of providing easier access to them.
Monorepos support an organizational culture of collaboration and support. When code is shared inside a monorepo, it means the challenges different teams face are also shared, making it easier to solve them together.
听
Challenges
听
One of the main disadvantages of monorepos is performance. This is because combining code across different functions and contexts in a single repository can slow down code pull operations.
If there are several sub-projects in a repository, it鈥檚 important to consider that type integrations may become a challenge. It鈥檚 also useful to know in advance if there are DevOps teams or individuals who can facilitate this way of managing code.
Monorepos can make security difficult, because, unlike other types of repositories, here you are granting a person who may only work on part of the project complete access to a codebase. Ideally, there should be independence between mono-repo projects; the versioning of each one should be established from the beginning to make it easier to deal with issues such as integrations and team coordination in relation to the maintenance of different code bases.
It鈥檚 important to evaluate the scalability of a monorepo; doing so allows us to establish early strategies to mitigate potential challenges as we scale. A pattern that can be valuable in this context is .
If an organization decides it wants to move from a monorepo to a multi-repo, it鈥檚 important it鈥檚 aware that this could lead to significant costs in terms of both time and effort.
听
What is a multi-repo?
听
A multi-repo is a software development approach where different projects or components of a larger application are stored and managed as separate repositories. Each project or component has its own version control repository, allowing teams to work on them independently. This approach contrasts with a monorepo, where all code is stored in a single repository. Multi-repo setups are often used to maintain clear boundaries between projects, enabling teams to work autonomously on different parts of a system while also potentially reducing conflicts that might arise when making changes.
听
What are the benefits and challenges of using a multi-repo?
听
We鈥檝e already explored some of the benefits and challenges of monorepos. But to properly evaluate them it鈥檚 necessary to also recognize the pros and cons of their alternative.
听
Benefits
听
Security is one of the main benefits of using a multi-repo. This is because, unlike mono-repos, in this strategy it鈥檚 possible to grant specific and necessary permissions according to the specific scope of a project.
With a multi-repo, scalability should be much more feasible and manageable from the beginning. This is because projects are abstracted earlier.
Versioning is also almost instantaneous when you use a multi-repo 鈥 when you have separate environments in multiple different repositories, little coordination is required.
With a multi-repo it is much easier to assign ownership since, for example, each repository can satisfy a specific business domain.
The independence and performance provided by multi-repos makes it much easier for organizations to distribute their resources and evaluate results.
Migrating multi-repos to alternative ways of managing a codebase is much easier to do, compared to mono-repos
It鈥檚 much easier to do CI/CD with a multi-repo. This is because there is a basic separation, which makes it easier to facilitate resources between teams.
听
Challenges
听
Applying clean code and refactors can be difficult when you use a multi-repo. Although there are early workarounds to mitigate the way things are done between each team, code duplication is highly likely.
Running and are generally straightforward when using a multi-repo, but running end-to-end tests can be a challenge. This is because when you separate your codebase, you will inevitably require output from different repositories. Fortunately, this can be mitigated by having Quality Assurance () people on the team who are dedicated to testing the full flow of an application.
Managing dependencies can cause friction between teams if a periodic management strategy that allows teams to obtain and implement the latest versions is not established.
Although having separate teams has advantages 鈥 as we saw above 鈥 there are also some disadvantages. These include:
Isolation between equipment can undermine effective engineering practices and communication between people.
If you lack a robust onboarding culture, it can be very difficult to incorporate new members into the team in a successful and healthy way.
Prioritization is inevitable and will inevitably be present in each team, but it can be somewhat complex to manage when teams are separate. This is because听 each team will want to achieve its own objectives, but as is often the case in the software industry, problems are presented as bugs or differences of opinion. If priorities are managed effectively, it can be the difference between an environment of chaos and rivalry and co-creation and empathy.
Summary Comparing Mono-Repo And Multi-Repo
Symbology
鉁 (Benefit) = Represents something obtainable without much effort.
鈿狅笍 (Attention) = Represents something not easily obtainable.
鉂 (Challenge) = Represents something difficult to obtain.听听
听
Recommendations
听
I have shown you the challenges and benefits of both monorepos and multi-repos. To conclude, I would like to share with you some recommendations for both scenarios, based on my experience.
听
Mono-Repo
听
Today, tools like and can help us manage generic web applications, or even micro front-end and mobile applications from a monorepo in a much easier manner than we were able to previously. I recommend exploring them..
Establishing a culture of good documentation from the start will go a long way towards successful onboarding.
In the same way, it鈥檚 important to consider that the pull request process, dependency management and quality may be affected, when this type of repository contains 鈥 or could contain in the future 鈥 a large number of projects. We have to consider and reflect on this when considering a monorepo as an option.
听
Multi-Repo
听
I recommend generating standards and establishing good practice from the beginning. Doing so will reduce inconsistencies in how code is written and implemented. This can be done through a wiki (using a tool like ), to document and articulate team consensus.
I also suggest implementing a consistent and dynamic design system early on if you decide to use a multi-repo. It can be very helpful when managed well.
听
Disclaimer: The statements and opinions expressed in this article are those of the author(s) and do not necessarily reflect the positions of 黑料门.