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.

This talk has been presented at DevOps.js Conf 2022, check out the latest edition of this JavaScript Conference.

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
NPM workspaces help manage multiple nested packages within a single top-level package, improving since the release of NPM CLI 7.0. You can easily add dependencies to workspaces and handle duplications. Running scripts and orchestration in a monorepo is made easier with NPM workspaces. The npm pkg command is useful for setting and retrieving keys and values from package.json files. NPM workspaces offer benefits compared to Lerna and future plans include better workspace linking and adding missing features.
Automating All the Code & Testing Things with GitHub Actions
React Advanced 2021React Advanced 2021
19 min
Automating All the Code & Testing Things with GitHub Actions
Top Content
We will learn how to automate code and testing with GitHub Actions, including linting, formatting, testing, and deployments. Automating deployments with scripts and Git hooks can help avoid mistakes. Popular CI-CD frameworks like Jenkins offer powerful orchestration but can be challenging to work with. GitHub Actions are flexible and approachable, allowing for environment setup, testing, deployment, and custom actions. A custom AppleTools Eyes GitHub action simplifies visual testing. Other examples include automating content reminders for sharing old content and tutorials.
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
DevOps is a journey that varies for each company, and remote work makes transformation challenging. Pull requests can be frustrating and slow, but success stories like Mateo Colia's company show the benefits of deploying every day. Challenges with tools and vulnerabilities require careful consideration and prioritization. Investing in documentation and people is important for efficient workflows and team growth. Trust is more important than excessive control when deploying to production.
Why is CI so Damn Slow?
DevOps.js Conf 2022DevOps.js Conf 2022
27 min
Why is CI so Damn Slow?
Slow CI has a negative impact on productivity and finances. Debugging CI workflows and tool slowness is even worse. Dependencies impact CI and waiting for NPM or YARN is frustrating. The ideal CI job involves native programs for static jobs and lightweight environments for dynamic jobs. Improving formatter performance and linting is a priority. Performance optimization and fast tools are essential for CI and developers using slower hardware.
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
Today's Talk discusses rethinking CI in monorepos, with a focus on leveraging the implicit graph of project dependencies to optimize build times and manage complexity. The use of NX Replay and NX Agents is highlighted as a way to enhance CI efficiency by caching previous computations and distributing tasks across multiple machines. Fine-grained distribution and flakiness detection are discussed as methods to improve distribution efficiency and ensure a clean setup. Enabling distribution with NX Agents simplifies the setup process, and NX Cloud offers dynamic scaling and cost reduction. Overall, the Talk explores strategies to improve the scalability and efficiency of CI pipelines in monorepos.
The Zen of Yarn
DevOps.js Conf 2022DevOps.js Conf 2022
31 min
The Zen of Yarn
Let's talk about React and TypeScript, Yarn's philosophy and long-term relevance, stability and error handling in Yarn, Yarn's behavior and open source sustainability, investing in maintenance and future contributors, contributing to the JavaScript ecosystem, open-source contribution experience, maintaining naming consistency in large projects, version consistency and strictness in Yarn, and Yarn 4 experiments for performance improvement.

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.