1001 Packages – Strategies for Managing Monorepos

Rate this content
Bookmark

When working with a monorepo, there are multiple Challenges: packages installation, packages linking, development processes (build, lint, testing) and deployment processes. Those challenges vary the type of artifacts in our monorepo (micro services, FE App, packages etc.). We will explore different approaches and tools for monorepos and their pro and cons.

FAQ

In the JavaScript world, a monorepo is defined as one repository containing multiple connected package JSON files. This setup forms a graph of all the internal packages and how they are interconnected, which is crucial for understanding the complexities involved in managing a monorepo.

Strategies for managing monorepos include defining the scope of the repository, deciding on the release pace or cadence, choosing appropriate build strategies, and determining development processes such as testing and linting. Additionally, linking between packages and deciding on installation methods for dependencies are critical strategies.

Common tools for managing monorepos include Lerna, NX, and TurboRepo for orchestration and build optimization, along with package managers like Yarn and PNPM that help with package linking and dependency management.

Advantages of using a monorepo include ease of code sharing across different parts of a project, atomic commits that can modify multiple packages simultaneously, and unified publishing that allows all packages to be deployed or published at once.

Challenges of using a monorepo include managing a large codebase with numerous commits, difficulty navigating and understanding changes made by different teams, security policy enforcement, and increased risk of tightly coupling different parts of the software.

In a monorepo, changes can trigger selective builds based on dependencies within the repo, potentially using cached builds for efficiency. In contrast, a polyrepo often requires building and publishing each repository independently, which can lead to duplicated efforts and less coherence in versioning and dependency management.

Configurations for different environments in a monorepo can be managed through centralized workspace settings that define build, test, and deployment processes. This approach ensures consistency across the different packages and applications within the monorepo.

In a JavaScript monorepo, package JSON files identify individual artifacts or packages within the repository. These files define dependencies and are interconnected to form a direct acyclic graph, representing the relationships between different parts of the application or library.

Tally Barak
Tally Barak
24 min
25 Mar, 2022

Comments

Sign in or register to post your comment.

Video Summary and Transcription

This Talk discusses strategies for managing monorepos, including release strategies, building strategies, development processes, and linking packages. The speaker highlights the challenges and complexities of monorepos, such as large codebases and potential coupling of software parts. They also mention the importance of suitable tooling for successful monorepo management and the potential for standardization in the future. Additionally, the speaker shares their personal journey in programming, starting at a young age and expressing their love for the field.

1. Introduction to Monorepos

Short description:

When I think about a monorepo, I think about an elephant. So my name is Tali Barak, I work for Youbeak. Today we're going to talk about strategies for managing monorepos and how do we tackle that. In the mono repo world, we have still the same one repository in the source control, but we are generating multiple artifacts from the same repository. In the JavaScript world, a mono repo is one repository with multiple connected package JSONs. It is crucial to understand the complexities that we encounter with a mono repo, which is a Direct Acyclic Graph.

When I think about a monorepo, I think about an elephant. You might think this is because a monorepo is a big thing or because it's gray, also this one is red, but it's actually because of this story. The story about six blind people that are trying to figure out what is an elephant. So each one is touching another part of it and they try to understand whether it's a spear, it's a snake, it's a tree or what is this thing. And sometimes when I talk with people about monorepos, this is how I feel. Everyone sees it is slightly different.

So my name is Tali Barak, I work for Youbeak. And today we're going to talk about strategies for managing monorepos and how do we tackle that. It's called 1001 packages, but it's not just about packages.

So let's start, what is a monorepo? And you can see all kinds of definitions. So this is my definition. And in order to understand that, we need to understand what is an artifact. And in our world, an artifact, you need to have this definition, a dictionary definition. An artifact is an object made by a human being. But in fact, when we talk in the software, we're talking about things like packages, tools, website or front end application, maybe a mobile application, a back end server or part of a server, which is a service, all of these are artifacts.

And traditionally, we would have one repository. And from each repository in your source control, you would create a single artifact of the above. In the mono repo world, we have still the same one repository in the source control, but we are, in fact, generating multiple artifacts from the same repository. But if we try and focus and this is a DevOps JS conference and we are talking about the JavaScript world, it actually means that in one repository, we would have multiple package JSON, because what identifies in the JavaScript world an artifact is a package JSON file. So this is our mono repo.

But there is one more thing. If we have a mono repo that looks something like that, it is likely that one package JSON, let's say inside foo, would point to another package JSON, there would be a dependency inside this mono repo. So here is my definition for a mono repo in the JavaScript world. One repository with multiple connected package JSONs. And in fact, what we have in the mono repo is this kind of graph of all the internal packages and how they are connected. And this is crucial to understand all the complexities that we later encounter with a mono repo. This is called a DAG, a Direct Acyclic Graph. That's because we have each package pointing to another. And hopefully there are no cycles because that's not a really good thing. And we are familiar with the tools even in this conference.

2. Strategies for Managing Monorepos

Short description:

A few tools like LearnA, NX, Yarn, PNPM, and TurboRepo help us deal with mono repos. Before deciding on a tool, let's discuss the strategies to employ in our mono repo. The common use cases include open source tools, microservices, and design systems. Monorepos offer easy code sharing, atomic commits, unified publishing, and deployment. However, they also come with challenges such as a large codebase, difficulty in tracking changes, security concerns, and potential coupling of software parts. Despite these challenges, let's explore the strategies for treating a monorepo, starting with the release strategy and its application in microservices.

A few of them were discussed. We have tools like LearnA and NX. We know about the package manager like Yarn and PNPM and tools like TurboRepo. And all of them are great tools that help us deal with mono repos.

But before we jump and decide which tool is best for us, let's stop. And let's talk about what are the strategies that we want to employ in our mono repo? And I'm a developer, so I start with zero when I do accounting.

And the first strategy is about scope. What do we want to have in our mono repo? And the common use cases that we see are things like open source tools. We have plenty of them. There are really a lot of the tools that we know and work with are built as a mono repo micro service, having multiple applications design system can be also a great use case for a mono repo. Or just as we know from the Google Facebook discipline, just put all of the company code in one place, but that's not a requirement for a mono repo.

And should I or should I not use the mono repo? And there are two great articles, one a repo, please do and mono repo, please don't. So the good thing about monorepo is that it is easy to share the code. You can run, you can make changes, which are atomic commits and are changing multiple packages or multiple projects at once. You can have a unified publishing and just be able to deploy or publish all of your packages at once. But we know one thing very well, there are no free lunches. So, with the good things come some other things that can challenge us. To start with, it's a large codebase, large codebase has lots of commit. Maybe lots of people are working on it. It's not always easy to find your way around and see what everyone did. Also, if you need some security policy and you don't want people to access certain kinds of the repository, then monorepo is not the good tool to use. And also, the fact that all the code is stored in one place might encourage people to couple the different parts of the software more than it is acceptable. And of course there are all the configuration, it's also for monorepo and when you use the repo, you will encounter some challenges.

But let's say that you decided that you actually want that. Yes, I will go with the monorepo. So, let's discuss now about what are the strategies that you want to have when you decide and what are the ways that you should treat your monorepo. And let's start with the first strategy, which is the release. So let's take two common use cases that people use monorepo for. The first one is having microservices. So you can have multiple services that are all stored in your repository and with some packages that those services depend on.

Check out more articles and videos

We constantly think of articles and videos that might spark Git people interest / skill us up or help building a stellar career

Levelling up Monorepos with npm Workspaces
DevOps.js Conf 2022DevOps.js Conf 2022
33 min
Levelling up Monorepos with npm Workspaces
Top Content
Learn more about how to leverage the default features of npm workspaces to help you manage your monorepo project while also checking out some of the new npm cli features.
Automating All the Code & Testing Things with GitHub Actions
React Advanced Conference 2021React Advanced Conference 2021
19 min
Automating All the Code & Testing Things with GitHub Actions
Top Content
Code tasks like linting and testing are critical pieces of a developer’s workflow that help keep us sane like preventing syntax or style issues and hardening our core business logic. We’ll talk about how we can use GitHub Actions to automate these tasks and help keep our projects running smoothly.
Fine-tuning DevOps for People over Perfection
DevOps.js Conf 2022DevOps.js Conf 2022
33 min
Fine-tuning DevOps for People over Perfection
Top Content
Demand for DevOps has increased in recent years as more organizations adopt cloud native technologies. Complexity has also increased and a "zero to hero" mentality leaves many people chasing perfection and FOMO. This session focusses instead on why maybe we shouldn't adopt a technology practice and how sometimes teams can achieve the same results prioritizing people over ops automation & controls. Let's look at amounts of and fine-tuning everything as code, pull requests, DevSecOps, Monitoring and more to prioritize developer well-being over optimization perfection. It can be a valid decision to deploy less and sleep better. And finally we'll examine how manual practice and discipline can be the key to superb products and experiences.
Why is CI so Damn Slow?
DevOps.js Conf 2022DevOps.js Conf 2022
27 min
Why is CI so Damn Slow?
We've all asked ourselves this while waiting an eternity for our CI job to finish. Slow CI not only wrecks developer productivity breaking our focus, it costs money in cloud computing fees, and wastes enormous amounts of electricity. Let’s take a dive into why this is the case and how we can solve it with better, faster tools.
The Zen of Yarn
DevOps.js Conf 2022DevOps.js Conf 2022
31 min
The Zen of Yarn
In the past years Yarn took a spot as one of the most common tools used to develop JavaScript projects, in no small part thanks to an opinionated set of guiding principles. But what are they? How do they apply to Yarn in practice? And just as important: how do they benefit you and your projects?
In this talk we won't dive into benchmarks or feature sets: instead, you'll learn how we approach Yarn’s development, how we explore new paths, how we keep our codebase healthy, and generally why we think Yarn will remain firmly set in our ecosystem for the years to come.
End the Pain: Rethinking CI for Large Monorepos
DevOps.js Conf 2024DevOps.js Conf 2024
25 min
End the Pain: Rethinking CI for Large Monorepos
Scaling large codebases, especially monorepos, can be a nightmare on Continuous Integration (CI) systems. The current landscape of CI tools leans towards being machine-oriented, low-level, and demanding in terms of maintenance. What's worse, they're often disassociated from the developer's actual needs and workflow.Why is CI a stumbling block? Because current CI systems are jacks-of-all-trades, with no specific understanding of your codebase. They can't take advantage of the context they operate in to offer optimizations.In this talk, we'll explore the future of CI, designed specifically for large codebases and monorepos. Imagine a CI system that understands the structure of your workspace, dynamically parallelizes tasks across machines using historical data, and does all of this with a minimal, high-level configuration. Let's rethink CI, making it smarter, more efficient, and aligned with developer needs.

Workshops on related topic

React at Scale with Nx
React Summit 2023React Summit 2023
145 min
React at Scale with Nx
Top Content
Featured WorkshopFree
Isaac Mann
Isaac Mann
We're going to be using Nx and some its plugins to accelerate the development of this app.
Some of the things you'll learn:- Generating a pristine Nx workspace- Generating frontend React apps and backend APIs inside your workspace, with pre-configured proxies- Creating shared libs for re-using code- Generating new routed components with all the routes pre-configured by Nx and ready to go- How to organize code in a monorepo- Easily move libs around your folder structure- Creating Storybook stories and e2e Cypress tests for your components
Table of contents: - Lab 1 - Generate an empty workspace- Lab 2 - Generate a React app- Lab 3 - Executors- Lab 3.1 - Migrations- Lab 4 - Generate a component lib- Lab 5 - Generate a utility lib- Lab 6 - Generate a route lib- Lab 7 - Add an Express API- Lab 8 - Displaying a full game in the routed game-detail component- Lab 9 - Generate a type lib that the API and frontend can share- Lab 10 - Generate Storybook stories for the shared ui component- Lab 11 - E2E test the shared component
Node Monorepos with Nx
Node Congress 2023Node Congress 2023
160 min
Node Monorepos with Nx
Top Content
WorkshopFree
Isaac Mann
Isaac Mann
Multiple apis and multiple teams all in the same repository can cause a lot of headaches, but Nx has you covered. Learn to share code, maintain configuration files and coordinate changes in a monorepo that can scale as large as your organisation does. Nx allows you to bring structure to a repository with hundreds of contributors and eliminates the CI slowdowns that typically occur as the codebase grows.
Table of contents:- Lab 1 - Generate an empty workspace- Lab 2 - Generate a node api- Lab 3 - Executors- Lab 4 - Migrations- Lab 5 - Generate an auth library- Lab 6 - Generate a database library- Lab 7 - Add a node cli- Lab 8 - Module boundaries- Lab 9 - Plugins and Generators - Intro- Lab 10 - Plugins and Generators - Modifying files- Lab 11 - Setting up CI- Lab 12 - Distributed caching
Deploying React Native Apps in the Cloud
React Summit 2023React Summit 2023
88 min
Deploying React Native Apps in the Cloud
WorkshopFree
Cecelia Martinez
Cecelia Martinez
Deploying React Native apps manually on a local machine can be complex. The differences between Android and iOS require developers to use specific tools and processes for each platform, including hardware requirements for iOS. Manual deployments also make it difficult to manage signing credentials, environment configurations, track releases, and to collaborate as a team.
Appflow is the cloud mobile DevOps platform built by Ionic. Using a service like Appflow to build React Native apps not only provides access to powerful computing resources, it can simplify the deployment process by providing a centralized environment for managing and distributing your app to multiple platforms. This can save time and resources, enable collaboration, as well as improve the overall reliability and scalability of an app.
In this workshop, you’ll deploy a React Native application for delivery to Android and iOS test devices using Appflow. You’ll also learn the steps for publishing to Google Play and Apple App Stores. No previous experience with deploying native applications is required, and you’ll come away with a deeper understanding of the mobile deployment process and best practices for how to use a cloud mobile DevOps platform to ship quickly at scale.
MERN Stack Application Deployment in Kubernetes
DevOps.js Conf 2022DevOps.js Conf 2022
152 min
MERN Stack Application Deployment in Kubernetes
Workshop
Joel Lord
Joel Lord
Deploying and managing JavaScript applications in Kubernetes can get tricky. Especially when a database also has to be part of the deployment. MongoDB Atlas has made developers' lives much easier, however, how do you take a SaaS product and integrate it with your existing Kubernetes cluster? This is where the MongoDB Atlas Operator comes into play. In this workshop, the attendees will learn about how to create a MERN (MongoDB, Express, React, Node.js) application locally, and how to deploy everything into a Kubernetes cluster with the Atlas Operator.
Azure Static Web Apps (SWA) with Azure DevOps
DevOps.js Conf 2022DevOps.js Conf 2022
13 min
Azure Static Web Apps (SWA) with Azure DevOps
WorkshopFree
Juarez Barbosa Junior
Juarez Barbosa Junior
Azure Static Web Apps were launched earlier in 2021, and out of the box, they could integrate your existing repository and deploy your Static Web App from Azure DevOps. This workshop demonstrates how to publish an Azure Static Web App with Azure DevOps.