DEV Community

Cover image for Do you use a monorepo?
Patryk Jeziorowski
Patryk Jeziorowski

Posted on

Do you use a monorepo?

I'm curious how many of you (and how, if so) use a monorepo. Do you use it for both backend and frontend? Do you use any tools to help you with that?

I would be grateful for your answers.

Top comments (19)

Collapse
 
sebbdk profile image
Sebastian Vargr • Edited

I've used it twice commercially, 1 fail and 1 success.

My TL;DR opinion
For small teams with highly mutable code bases it is convenient, especially in the first couple of stages of life for commercial projects. Less parts, more speed!

For large teams/application it quickly becomes a testing nightmare where everyone hates that team that broke their feature, again.

The large team/application problem can be mitigated, but to do it you need dedicated technical leads or an experienced team on top of enforced standards.


Here are my experiences from different points in my career.

Company 1:
As a intermediate developer i worked in a team of
15-25+ people in a repo', with very unrelated parts that would break frequently when common code was touched. Enforcing coding styles was a nightmare because of how many people you needed to include. The performance was out of control because we could not isolate parts or make informed group decisions on libraries.

Developer experience was from junior to intermediate, and 1 socially inept senior.
Everyone making technical decisions and working their own patterns rather than a common one.

Making releases was problematic, and feature integration bugs were rampant, mitigated by a large QA team.

Worth mentioning, technical leadership was basically non-existent here, leading to constant chaos.

Company 2:
As a senior developer i worked in a team of
10-15 people working in a repo', 3 teams each responsibly for a isolated part of the code-base, and only senior developers with a high focus on performance and maintaining standards, i would go as far and say we had a performance culture.

It worked well, mostly because each part we made was mostly isolated, so breaking unrelated parts was uncommon unless you bodged a bug-fix for a library part.

Technical leadership was also missing in this case, but mitigated by the number of seniors, culture, smaller team and somewhat smaller code-base.

Collapse
 
kwstannard profile image
Kelly Stannard

I have experienced this. Is it really a mono repo if there is one monolithic application though? One app per repo I would just say is a normal repo.

Collapse
 
sebbdk profile image
Sebastian Vargr • Edited

Afaik mon-repo refers to the practice of having all related application code in the one (mono) repo.
vs separating API's, libraries, etc. into different repositories.

Am i wrong about that interpretation?


You are right tho, the first example would not fit that description strictly, as some dependencies were external (Authentication and API).

It did encompass several unrelated web applications in the same codebase however.

My second example contains all the related source code in one repo, so would fit the description more accurately.

Collapse
 
iilness2 profile image
andre aliaman

not really. you can still use monorepo for microservices. since what you want to build based on the path you can mention (mostly) on config.

Thread Thread
 
sebbdk profile image
Sebastian Vargr • Edited

Can you be more descriptive, how it is it "not really". :)

Collapse
 
mikenikles profile image
Mike

Hey Patryk,

My personal website uses a monorepo for both the frontend and the backend. The source code is available at github.com/mikenikles/www-mikenikl.... As a follow up, I created a monorepo template at github.com/mikenikles/monorepo-tem....

Each service currently has its own dependencies, so it's not truly a monorepo with shared dependencies across all services. However, I'm writing a book on cloud native web development at the moment and for that, I am updating the monorepo template to include shared dependencies and a CI / CD pipeline that automatically determines which services to build and deploy based on the changes in each git commit.

You can tell, I've had positive experiences with monorepos despite the initial challenges they come with, especially in larger teams. However, with the right attitude, team structures and guidelines in place, I continue to believe the pros outweigh the cons in the monorepo debate.

Do reach out if you have questions.

Collapse
 
deimosfr profile image
Pierre Mavro

Don't you think "the right attitude, team structures and guidelines in place" cost too much for most of the companies?

Only a small amount have the problematic like Google of Facebook and require monorepo. From my POV, I've never really used monorepo, but it looks like there is no really consensus on how to manage it, CI/CD are not adapted to it...it cost a lot of time to handle it.

Correct me if I'm wrong, I'll be also happy to get feedbacks of persons who really are using it and can bring clear advantages.

Collapse
 
mikenikles profile image
Mike

I agree with you, this is a balancing act between cost of maintaining multiple repositories and cost of implementing a monorepo, training the team and putting guidelines in place.

Especially with a lack of best practices and a lack of well documented how-to experiences, this is quite a bit of investment a team or company has to put in.

In my personal experience with monorepos of 15 to 20 engineers who work in it, that initial monorepo setup has been beneficial in the long run. However, I too am interested to hear from others who have hands-on monorepo experience.

Collapse
 
pjeziorowski profile image
Patryk Jeziorowski

Hey Mike,

thanks a lot for your valuable answer. I'll definitely study your template tonight. I wonder what's the way to build a CI/CD pipeline that is suitable for all kind of monorepos, not just JS focused. It seems like monorepos are most popular in JS world with tools like lerna, and even in JS ecosystem you can find various ways to do monorepos (there's no commonly accepted standard).

Collapse
 
mikenikles profile image
Mike

I can't comment on a multi-language monorepo as I don't have experience with that. My main focus is in the JavaScript ecosystem. This definitely makes the monorepo situation much simpler compared to a multi-language monorepo.

Collapse
 
jessekphillips profile image
Jesse Phillips

We use the term monorepo, but this was done for transition of on project into two repositories. Management will be very confused if there comes a time we tried to create only one.

We also have a third for the backend and this tends to take on what might be considered another project, like the DB scripts.

Our repos are also forked per client, it is very hard to get all the devs to agree to stay up-to-date and how that actually improves quality even with the risk of breaking something. (QA here trying to build automation, consistent across clients to reduce upgrade failures.)

Collapse
 
pjeziorowski profile image
Patryk Jeziorowski

Is your backend just one application? Or it's a set of micro apps in one repository?

Collapse
 
jessekphillips profile image
Jesse Phillips

Actually it really is not a mono repo, let me just start over on that one.

Think any plug in platform, like Jenkins. We have the platform, it has its own development team and release.

We then have components which have their own repo. Finally we have the repo which I was talking about. It uses the nuget packages from the components, supplies their configuration and wire up into the platform.

So no not really mono and not really separate applications.

Collapse
 
baso53 profile image
Sebastijan Grabar

What exactly is a monorepo and what are its advantages?

Collapse
 
patarapolw profile image
Pacharapol Withayasakpunt

monorepo only make sense if all sub repositories are in only one language. And I know only one language doing this, JavaScript.

For JavaScript, all modules are shared, that is, only one node_modules folder, ensuring all dependencies' versions are the same.

Collapse
 
pjeziorowski profile image
Patryk Jeziorowski

I'm not sure if it's true that it makes sense only with Javascript, there are huge companies like Google that use it with multiple languages.

But being such a giant as Google allows you to do crazy things.

I'm curious if in small/medium size projects monorepos are popular only in Javascript ecosystem (if we take only small/medium projects into account, then I agree that only JS makes any sense. I think this is the only language that has any tools for doing this anyway?).

Collapse
 
sebbdk profile image
Sebastian Vargr • Edited

I think i can see were you are coming from but,
lets look at some stories to explore this more. :)

  • As a developer i want to pull 1 repository and then i expect to have all the necessary first-party code available to run a given project.
  • As a developer i would expect to change first-party code within a project without having to consider version matching it with other first-party parts.
  • As a developer i want to be able to write integration test between first-party parts without having to manage parts versions.
  • As a developer when i make a PR with a feature i would expect all the changes to be in that PR.

Imagine a stack with a C# API server or headless CMS, a couple of FE's intended for different user groups, like end-user or admin.

Add in some machine learning , written in Python that the C# needs to interact with occasionally.

Very quickly, monorepo starts to become the only way, i can think of, that handles these stories. :)

Collapse
 
pjeziorowski profile image
Patryk Jeziorowski

Instead of creating a separate repository for each app, you keep most of your code in one repository.

Pros: all your codebase in one place, you see dependencies across projects, you can make changes across projects etc.

Cons: there is no tooling for managing it easily (IMO) besides maybe Javascript, problems with CI/CD

Collapse
 
patarapolw profile image
Pacharapol Withayasakpunt • Edited

Currently, I use pseudo-monorepo, not monorepo anymore.

I use no Lerna, no Workspaces, and separate node_modules folders.

Actually, I think we shouldn't use a monorepo for frontend and backend, because browsers' and Node's dependencies can be vastly different. Backend only, or frontend only is OK.