Say bye to monorepos say hello to megarepos
Tags: monorepo, lerna, javascript, megarepo
Published: 2019-11-04 14:45:42

---
title: Say bye to monorepos say hello to megarepos
published: true
date: 2019-11-02 22:18:33 UTC
tags: monorepo, lerna, javascript, megarepo
canonical_url: https://www.jonathancreamer.com/say-bye-to-monorepos-say-hello-to-megarepos/
---

<img src="https://www.jonathancreamer.com/content/images/2019/11/IMG_2348.JPG" alt="Say bye to monorepos say hello to megarepos"><p>Breaking up a monolith can be a daunting task. Oftentimes a monolith gets broken up into many repos, and sometimes into a monorepo.</p><p>But, here's the problem I have with the term monorepoo.</p><blockquote>Monorepos are NOT monoliths!</blockquote><p>I recently heard a talk by Marcel Cutts called... <a href="https://www.youtube.com/watch?v=rdeBtjBNcDI&amp;amp=&amp;feature=youtu.be">MonoRepos for the Masses</a>. It's a great talk about the history of monorepos and big companies using them. I LOVED that talk. Definitely give it a listen. </p><p> Mono, obviously is a word that comes from latin which means, "one". The fact that the word "mono" is used in both monorepo, and monlith, tends to lend itself to a lot of confusion. </p><h2 id="monolith">MonoLITH</h2><p>First, off, monolith in an of itself might not be a bad thing for your company/team. There are a lot of companies, particularly startups, that have done great things with monoliths. In fact, Martin Fowler notes that most microservice architectures that started as microservice vs starting as a monolith and getting broken up, tend to result in bad architectures.</p><figure class="kg-card kg-bookmark-card"><a class="kg-bookmark-container" href="https://martinfowler.com/bliki/MonolithFirst.html"><div class="kg-bookmark-content"><div class="kg-bookmark-title">bliki: MonolithFirst</div><div class="kg-bookmark-description">Going directly to a microservices architecture is risky, so consider building a monolithic system first. Split to microservices when, and if, you need it.</div><div class="kg-bookmark-metadata"><span class="kg-bookmark-author">Martin Fowler</span><span class="kg-bookmark-publisher">martinfowler.com</span></div></div><div class="kg-bookmark-thumbnail"><img src="https://martinfowler.com/bliki/images/microservice-verdict/path.png" alt="Say bye to monorepos say hello to megarepos"></div></a></figure><p>However, I think the drawback starts to happen when you get to a point where hundreds of folks are constantly working and committing code into it. You can very easily end up with the [Big Ball of Mud](<a href="https://exceptionnotfound.net/big-ball-of-mud-the-daily-software-anti-pattern/">https://exceptionnotfound.net/big-ball-of-mud-the-daily-software-anti-pattern/</a>) anti-pattern. A monolith can be come a castle housing your most precious of code; an impenetrable fortress surrounded by a crocodile filled moat of unforgiving technical debt.</p><p>If you're not careful, very tight coupling between different parts of the monolith can make it impossible to ship one part of the application without shipping the whole thing, and make it very difficult to refactor into smaller pieces as well.</p><h2 id="monorepo">MonoREPO</h2><p>Here's where things get interesting. So, yes, the word "mono" exists in both places, but that's not to say that they do and serve the same exact purpose. There are a lot great reasons to keep all of your code in a single repository, just like you would in a monolith.</p><p>The distinction however though is that, unlike a monoLITH, a monoREPO is <em>usually</em> just a lot of packages sharing the same code base. Some of these packages are dependent on other packages sure, but in no way does the monorepo have to ship all at once as is the case with a monolith. Nor does it mean that the repo is a big ball of mud with muddied concerns, and tight coupling.</p><p>It's for the above reasons that the term monorepo should be replaced by "megarepo". </p><h2 id="s-mono-mega-">s/mono/mega/</h2><figure class="kg-card kg-embed-card"><blockquote class="twitter-tweet"><p lang="en" dir="ltr">I propose we call them &quot;megarepos&quot; going forward. Too many people conflate the term &quot;monolith&quot; with &quot;monorepo&quot;. Let&#39;s fix it. <a href="https://twitter.com/hashtag/divops?src=hash&amp;ref_src=twsrc%5Etfw">#divops</a></p>&mdash; Jonathan Creamer (@jcreamer898) <a href="https://twitter.com/jcreamer898/status/1189887019020894208?ref_src=twsrc%5Etfw">October 31, 2019</a></blockquote>
<script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>
</figure><p>The mono/mega repo should be defined as...</p><blockquote>A bunch of packages in once place with shared tooling to facilitate collaboration, increase productivity, and create a single culture.</blockquote><p>A few highlights from using a megarepo are:</p><ul><li>Consistent build tooling</li><li>Less context switching</li><li>Much MUCH easier to update shared code</li><li>Easier to affect change across the platform</li><li>Code reviews are centralized<br></li></ul><p>In the wonderful world of a megarepo, you can in fact see the forest for the trees. Meaning, you get a sense of what all is available to you as a member of a larger organization. If the packages in your megarepo have tooling which enables them to be easily tested, shared, and used as isolated units, you end up in a world where your application itself is the component library. Disparate packages which, in a multirepo setup, might become difficult to discover are easy to find and work with as they are written, tested, and documented all in the same place.</p><p>The megarepo often has a group of shared dependencies as well. In the case of a frontend project with a React toolchain, the base level React version might be shared across packages, or there maybe shared components which have a shared version across packages. This is not a drawback of a mega, it's a plus! Now you get to live in a world where an update to a shared package can all at once have every single dependent package run a test suite to verify that it didn't break. This makes it so much easier to maintain consistency across your entire application.</p><p>Nothing is without its negative sides of course. There is no such thing as a silver bullet, and in no way is a megarepo the right thing for every team, in every situation. Just like any tool, it should be thought out extensively before put into practice. One of the biggest obstacles in working this way is, it requires a good deal more tooling to work with. So, if you're at a company where there's no team managing the platform of the megarepo itself, it can be a difficult task to maintain it.</p><p>That being said, when you do have a team dedicated to writing tools for the megarepo, it can be a fantastic option, and I have to give credit to <a href="https://twitter.com/benmvp">Ben Ilegbodu</a>, and <em>maybe</em> <a href="https://twitter.com/kylewelch">Kyle Welch</a> for helping me come up with the term.</p><figure class="kg-card kg-embed-card"><blockquote class="twitter-tweet"><p lang="en" dir="ltr">I&#39;ll give you microapps but megarepos was me. My how quickly revisionist history happens after leaving!<br><br>January 2020: &quot;Ben who???&quot;</p>&mdash; Ben Ilegbodu 🏀 (@benmvp) <a href="https://twitter.com/benmvp/status/1189943361785888769?ref_src=twsrc%5Etfw">October 31, 2019</a></blockquote>
<script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>
</figure><h2 id="conclusion">Conclusion</h2><p>A move away from the word monorepo will hopefully convey the fact that even though code might share the same repo, it is not in any way, a monolith.</p><p>I love the idea of creating a single culture, it was a great take away from Marcell's talk.</p><p>So, how about going forward, rather than talking about monorepos, we talk about megarepos, and how much benefit they can bring to a large team.</p><h2 id="-todo-write-a-post-about-how-to-implement-one">// TODO: write a post about how to implement one</h2><figure class="kg-card kg-bookmark-card"><a class="kg-bookmark-container" href="https://github.com/jcreamer898/blog-post-ideas/issues/1"><div class="kg-bookmark-content"><div class="kg-bookmark-title">How to successfully implement a megarepo · Issue #1 · jcreamer898/blog-post-ideas</div><div class="kg-bookmark-description">Needs to discuss options like Bolt and Lerna. Talk about the build tooling.</div><div class="kg-bookmark-metadata"><img class="kg-bookmark-icon" src="https://github.githubassets.com/favicon.ico" alt="Say bye to monorepos say hello to megarepos"><span class="kg-bookmark-author">jcreamer898</span><span class="kg-bookmark-publisher">GitHub</span></div></div><div class="kg-bookmark-thumbnail"><img src="https://avatars3.githubusercontent.com/u/472487?s=400&amp;v=4" alt="Say bye to monorepos say hello to megarepos"></div></a></figure><p>Any other topics you want to hear more about?</p><p><a href="https://github.com/jcreamer898/blog-post-ideas/issues/new">Add an idea</a>.</p>