Microservices: Pros and Cons of Mono repos
Recently, there was an interesting question on Quora on Microservices – What companies use a mono repo but deploy as microservices?
The real question is hidden behind those words – Is it ok to use Mono repos to store Microservices code?
At first sight, it appears that Microservices and Mono repos are at odds with each other. Does it make sense to have Microservices code in a mono repo when they are going to be deployed independent of each other?
Do any companies use this style of operation?
Yes, they do!
- Facebook have mono repo as per this post – Scaling Mercurial at Facebook.
- Google is rumoured to have mono repo (as indicated by many posts), but I can’t be sure as I haven’t worked there.
- Shippable on their blog mention that they have a mono repo. In fact, they moved from multiple repositories to a mono repo.
The most important result of using Microservices architecture should be that each of the services must be fully autonomous i.e. they must not have any design time dependencies.
All other considerations vary from company to company. Some such considerations are:
- The meaning of Application: A statement made by Martin Fowler captures the essence of Microservices perfectly – “In short, the microservice architectural style is an approach to developing a single application as a suite of small services”. The key words from being “Single application”. At the end of the day, all the microservices are contributing to form a single application. For some people, it makes more sense to have all the source code in one place because an individual service on its own might have no meaning.
- Code style: Some companies find it useful to have a consistent coding format enforced across all their code. This is certainly more difficult to achieve when you have separated repositories. This is especially true of companies that are dependent on manual verification of code as against automated code quality checks.
- Testing: It is easier to create integration tests when you have all the services in one repository because creation of testing environment and deployment become easier.
Note that having a single repository comes with a number of drawbacks.
- CI and CD pipelines: Ideally, you would want your CI and CD pipelines for each microservice to be independent of each other. You would not want the entire build to fail if one of the services is having errors.
- Code dependencies: Difficult to avoid compile time dependencies. You would need a process or a person to make sure that no one is building services that are dependent on each other. At the same time, remember that mono repo does not mean tightly coupled code.
- Team dependencies: Following on from the above point, teams that share a single repository do not have complete freedom to make changes in the code as there are dependencies on other service’s code.
So, in summary, certain organization factors do exist that force having Microservices code in a mono repo. It is perfectly fine as long as proper guidelines exist to manage dependencies and ownership between code owned by different teams.
Reference: | Microservices: Pros and Cons of Mono repos from our JCG partner Deepak Karanth at the Software Yoga blog. |