Why use a monorepo?

Sdílet
Vložit
  • čas přidán 26. 07. 2024
  • Matt Pocock (@mattpocockuk) explains how debugging is faster, code editing is easier, and build processes are easier to understand after refactoring a polyrepo setup to a monorepo, and deploying it on Vercel. Try Turborepo: vercel.fyi/tryturbo
    0:00 The bug
    1:02 Polyrepo or monorepo?
    1:29 Creating a new monorepo
    2:01 Migrating the repos
    3:11 Setting up a turbo.json
    3:53 Fixing the bug
    4:11 Deploying to npm
    4:44 Deploying to Vercel
    6:03 Summary
    For more on Turborepo:
    ◆ Migrating to a monorepo: turborepo.org/docs/handbook/m...
    ◆ Publishing packages: turborepo.org/docs/handbook/p...
    ◆ Building apps: turborepo.org/docs/handbook/b...
    #monorepo
  • Věda a technologie

Komentáře • 123

  • @FabianVilersBe
    @FabianVilersBe Před rokem +282

    Well, that's more a "How" than a "Why"...

    • @frontendtony
      @frontendtony Před rokem +12

      The why is kind of implied

    • @FabianVilersBe
      @FabianVilersBe Před rokem +48

      @@frontendtony Yeah, but there's more to say about the pros and cons to adopt a monorepo and the video title is a bit misleading in that regard ;-)

    • @michaellee3502
      @michaellee3502 Před rokem

      It improves the efficiency of your workflow so you spent more time programming and solving problems rather than administrating your repo

    • @LegitBanananas
      @LegitBanananas Před rokem +9

      Mono repo actually adds more administrative work not less in my opinion.

    • @GustavoDiaz93
      @GustavoDiaz93 Před rokem +1

      Matt just wanted to show off his math package hahaha, I agree the “why” is implicit which means video’s title is clickbait (kinda).

  • @chandragie
    @chandragie Před rokem +13

    His way of explaining is on another level!

  • @BritainRitten
    @BritainRitten Před rokem +53

    I love Matt's explainers. Very clear

  • @kasraghoreyshi
    @kasraghoreyshi Před rokem +2

    I've been very happy with Turborepo and have been using it for almost every solo project that I do. I like it's simplicity and ease of use.

  • @BorisBarroso
    @BorisBarroso Před rokem +7

    You can also use *patch-package* which is very simple to use and you can regress the changes you have made once the repo has been updated and you see the problem you fixed is gone.

  • @gmabber
    @gmabber Před 11 měsíci

    I love your teaching style. You rock!

  • @alir8zana635
    @alir8zana635 Před 8 měsíci

    this video was great
    It really demostrates the use of Turborepo very well

  • @FacePlat3
    @FacePlat3 Před rokem +5

    Thanks for the tutorial! If only this video was made before my suffering of having to publish and installing over and over again for my package, my life would have been easier 🤣.

  • @yoshinobuogawa9442
    @yoshinobuogawa9442 Před rokem

    Hell yeah man good work

  • @codewithguillaume
    @codewithguillaume Před rokem

    Thanks for that my friend

  • @ishanksharma9051
    @ishanksharma9051 Před rokem +1

    amazing video

  • @ginger-viking
    @ginger-viking Před rokem

    great video!

  • @Mikkelzu
    @Mikkelzu Před rokem +5

    quick question;
    If I were to have my Azure pipeline covering my monorepo, and each successful build would become a release, would turborepo consider a cached build (so out of my 2 apps I have, App1 is cached and App2 has changes to be rebuilt, alongside a ui package for shared react components lets say) a succesful build and thus cause a re-deployment for both apps? this is what my team is currently struggling with. Or is there a way we could emit the cache hit/missed to our pipeline so we can then have that determine wether or not to re-deploy

    • @hassanalthaf8561
      @hassanalthaf8561 Před rokem +1

      Hey, interesting question.
      This is pretty easy to solve with a mono-repo (there's a technology called Nx Monorepos). Our team picked Nx Monorepos because they ship with a "nx affected:*" command set that lets you to define what steps to follow when deploying on an individual app/library level through a pipeline by using the "nx affected:*" magic and only hitting the "deploy" process for apps/libraries that are TRULY affected by the change in your merge.
      However, you're right, it adds a load of trouble. It was a live and learn process for us, we still continue doing it.
      Would I recommend this? Depends. If you're just trying to bring in 2-3 repos into one mono-repo, then I'd say, not worth the trouble. If you have 5-10 repositories that you want to put together into 1 and each of them have decent changes frequently, then I'd say, yes, the pain of a mono-repo is worth it as you won't have to waste time publishing on one end, and then running your pipelines individually for each app for just bumping a package version.

  • @sadev0
    @sadev0 Před rokem

    great explanation

  • @merictunc
    @merictunc Před rokem

    Finally I get to know whole monorepo. I used to see packages folder under source I was wondering how do they manage it, now no more

  • @_vicary
    @_vicary Před rokem +12

    Despite not really explaining anything, I love how monorepo is bouncing back from the microservice era.

    • @mikopiko
      @mikopiko Před rokem

      Monolith for the win

    • @hojdog
      @hojdog Před rokem

      They're completely unrelated
      You can still have both a monorepo and microservices

    • @_vicary
      @_vicary Před rokem

      @@hojdog The era represents conventions and the hype within said period, like, living in COVID times doesn't make you COVID itself.
      I know, it's hard to believe.

  • @kevinzunigacuellar
    @kevinzunigacuellar Před rokem +2

    Amazing video Matt!

  • @BackInTheDayTunes
    @BackInTheDayTunes Před rokem +5

    What if your maths package is being used on 3 separate projects? That would mean bundling the maths package with all 3? This looks like it would be useful but only when theres a 1 to 1 relationship between package and app. Or am I really missing something here?

    • @elvinchu
      @elvinchu Před rokem +1

      Yes I am thinking that also

    • @cookie_doki
      @cookie_doki Před rokem

      yeah it doesnt make sense really. why even make a package if its only in 1 repo? you can just use two repos in one workspace while you are working on the npm package.

  • @CoryTheSimmons
    @CoryTheSimmons Před rokem +11

    TurboRepo half-heartedly supports Docker. It seems like an afterthought. Vercel doesn't support Docker at all. I'm not trying to be rude, but a monorepo having _something_ Docker is super common, and Render offers this. Does the TurboRepo/Vercel team have any plans for improving Docker support in the upcoming year?
    Specifically, I want to be able to put a docker-compose.yml in every app and/or package in my TurboRepo project, then deploy with something as simple as `$ vercel deploy`. I'd be sold for life.

  • @shaohaolin517
    @shaohaolin517 Před rokem

    Matt is hilarious 😊

  • @RichiAndiProject
    @RichiAndiProject Před rokem

    hanks lot Sir.. You helping us..

  • @justinoneill2837
    @justinoneill2837 Před rokem

    Does a _hybrid_ workflow exist where you have a "maths" package inside a private monorepo but also "maths" inside a public monorepo that can be shared?
    I use Turborepo and love it- but I'm in a situation where we're creating packages inside a private monorepo that I also need in my personal monorepo. I need a way to share that same package in both, make updates in both and pull in changes in both.
    Is this possible?

  • @aleksd286
    @aleksd286 Před rokem +10

    Haven't seen anything with nextjs with custom server (check NextJs docs/advanced-features/custom-server)
    That would be cool an example! Just saying. (Having huge troubles myself with it, its impossible to resolve workspace modules)

  • @Loserfr
    @Loserfr Před rokem +2

    My company has a monorepo with like 20 apps and I can't even block a PR if the CI doesn't pass (like for test or linter). I'm advocating for smaller multiple repos but they won't do it because "it would take too much time to migrate from one state to another".
    I don't see the point of a monorepo for more than 3-4 apps. I've worked in more than 15 stacks and still can't see any advantage of using a monorepo...

  • @lsagar
    @lsagar Před rokem +1

    Been using nx workspace for mono repo,
    Love it so far

    • @sarunmrzn
      @sarunmrzn Před rokem

      horrible experience with nx for me, some guy set it up before i joined the project and now all i get are angular related threads anything related to nx

    • @lsagar
      @lsagar Před rokem

      @@sarunmrzn it took me a while to figure out how everything is wired up. Once i got a mental model of what's going on, I love it even more

  • @TFDusk
    @TFDusk Před rokem +12

    I don't really see the benefit on the why. Maybe I'm misunderstanding it but this at least to me seems like it would introduce more problems in the future since now your project would be responsible for maintaining the code that you're using. Sure the example your giving is simple, but depending on the work this can easily be some specific call function that is dependent on a slew of other dependencies in that packages repository that they use on the side. Unless the projects abandoned and you can't find a good alternative, I feel like its better to leave off package maintanence to the maintainers of that project, and just PR fixes to that branch even if it takes hours to push.

    • @sviatoslavnovosiadlyi611
      @sviatoslavnovosiadlyi611 Před rokem +1

      I think it works well for that specific usecase. But if you have 10 apps using that library, having them all in 1 monorepo would be a mess.. Thanks but no

    • @justinoneill2837
      @justinoneill2837 Před rokem

      Does a _hybrid_ workflow exist where you have a "maths" package inside a private monorepo but also "maths" in its own public repo on Github so others could contribute?
      I use Turborepo and love it- but I'm in a situation where we're creating packages inside a private monorepo that I also need in my personal monorepo. I need a way to share that same package in both, make updates in both and pull in changes in both.
      Is this possible?

  • @RicoRioss
    @RicoRioss Před rokem +1

    what happen if i have many project and many package, can it make slow on build or start app on development?

  • @Mitsunee_
    @Mitsunee_ Před rokem +1

    Got a bit of a more complicated migration (if I even bother at this point), I have a bigger project in a monolithic repo with multiple scripts (check, prebuild, svgo prepare scripts and such) and utilities shared between backend and those scripts so I'd need some packages to have binaries and couldn't get that to work with yarn 1.x so far and having types accesible outside of packages has already been confusing enough with my current workaround requiring d.ts files in the packages root directory (even tho types get generated into dist... alongside the build). I also already have the next app deployed to vercel, so I'd need to change those settings.

  • @QiuqiuVG
    @QiuqiuVG Před rokem +1

    How is the maths repo configured? Is the example published?

  • @mahavirsingh-rh2te
    @mahavirsingh-rh2te Před rokem

    yo bro, really thankya. Big respect

  • @gamertike
    @gamertike Před rokem +1

    what is the actual advantages of turborepo over pnpms built-in workspaces?

  • @seanki
    @seanki Před rokem +3

    Inefficient for huge applications that have complex CI pipelines for fixing this type of problem. There are also other aspects to what type of architecture fits best, depends on use case.

  • @ezaezaeza4743
    @ezaezaeza4743 Před rokem

    Is there a real need to publish the package here ?
    On deployment, won't it be pulled from the monorepo directly ?

  • @stunna4498
    @stunna4498 Před rokem

    whats that vcscode letter theme-?

  • @midlight25
    @midlight25 Před rokem +21

    In my experience, monorepo if you're working alone and polyrepo if you're working as a team/group. But do be careful because monorepos, after they grow past a certain size, can cause tools like Git and other build tools to slow down/malfunction just because of the sheer amount of data they have to handle.

    • @hojdog
      @hojdog Před rokem +8

      I think you have it backwards. I single dev is more easily going to be able to manage polyrepos because they know when dependencies change.
      It’s big teams that get the most benefit from monorepos since dependencies change all the time and need to be kept in sync

  • @FunctionGermany
    @FunctionGermany Před rokem

    doesn't this problem already have a "native" solution with npm link or patch-package??

  • @jayshah5695
    @jayshah5695 Před rokem

    should add a video in versioning strategies and publish workflows of libs and apps in monorepos

  • @Narblo
    @Narblo Před rokem

    What about a repo with submodules?

  •  Před rokem +1

    why not use a "link"?

  • @mahadevovnl
    @mahadevovnl Před rokem

    So basically: you use a monorepo if you want to quickly develop multiple related projects together, of which one or multiple projects (in /packages) might also be published for others to use.
    My employer: "We will now dump everything into one massive monorepo and keep everything closed-source. All projects, related or not, go into one repository."
    Me: "... oh fuck, they're dumb."

  • @lucavogels
    @lucavogels Před rokem +15

    This seems much more work and looks way more complicated than just having two dedicated repos 😅

    • @conor909
      @conor909 Před rokem +6

      Use a monorepo and then come back and say this

    • @cookie_doki
      @cookie_doki Před rokem

      exactly. you dont need a monorepo to use workspaces. you can just add two repos to one workspace.

    • @conor909
      @conor909 Před rokem

      But then how do you share all the common build tools and configuration with team members?

    • @cookie_doki
      @cookie_doki Před rokem

      If you need to share the workspace config you can make that a repo as well. Not 100% sure how turbo will handle that but with yarn workspaces git will not commit every file from the individual repos. It just stores what commit each child repo is on and then you can commit your workspace config. IMO this makes way more sense when a package is being used in a lot of different projects. You can easily add and remove repos to and from your workspace.

    • @conor909
      @conor909 Před rokem

      @@cookie_doki I don’t see how that’s useful, if your code and packages aren’t all shared amongst each other and you can work in isolation happily, then you don’t need a monorepo

  • @DuyTran-ss4lu
    @DuyTran-ss4lu Před rokem

    Cool

  • @DaniAkash123
    @DaniAkash123 Před rokem

    I hate the fact that I have to maintain a separate build step for packages inside my monorepo which I'm not going to publish anyway

  • @webcodeuniversity
    @webcodeuniversity Před rokem +4

    We can do "yarn link" for instance , Monorepo isn't always the answer, but I'm a big fun of Monorepo though😉, but good marketing 👍

    • @rand0mtv660
      @rand0mtv660 Před rokem +1

      yarn/npm link is not powerful as this and it's more clunky to work with. Just linking cannot really detect dependencies and rebuild stuff in such a way that a monorepo setup with Turborepo or NX can.

    • @webcodeuniversity
      @webcodeuniversity Před rokem

      @@rand0mtv660 I know, but not in all use cases we'll have to use a monorepo, it just doesn't make any sense, it all ends on what you really need and if things need to setup a monorepo, I'm not against it as I'm using it as well in some projects, not all of them 🙃

    • @rand0mtv660
      @rand0mtv660 Před rokem +1

      @@webcodeuniversity Yeah for sure. I'm just saying that yarn link isn't really an equivalent to a monorepo. But what you are saying is definitely correct. Each tool has its purpose and monorepo isn't always the solution.

    • @webcodeuniversity
      @webcodeuniversity Před rokem +1

      ​@@rand0mtv660 sure thing, I agree. I mentioned "yarn link" just to say that monorepo isn't the right thing for everything, because I know some less experienced devs would take it for granted which is misleading. Thanks for your intervention though, it's been nice conversation 🤝

  • @ahmedel-mahrouky5913
    @ahmedel-mahrouky5913 Před rokem

    Installed, everything works, thanks!

  • @arturamorfati
    @arturamorfati Před rokem

    nice acting, my man😎

  • @mma93067
    @mma93067 Před rokem +1

    …git submodules exist tho

  • @ultimaweap12
    @ultimaweap12 Před rokem +2

    Ok, this is cool and all but what happens when another project needs to also use your maths repo?
    You pull it in my-monorepo as well?
    If it's a popular library in your company, I imagine that would get chaotic real quick.
    Also, what happens when there's ANOTHER library you want to use in the way you used maths repo? Let's say... foo repo.
    Foo repo already exists in another location, so by pulling into my-monorepo, you're just basically creating your own fork...
    It sounds like what you did in this video works great if you're making ONE application which requires ONE custom library, then you can tightly couple them together.
    Anything more complicated than that looks... messy.

  • @CoooLLer
    @CoooLLer Před rokem +2

    Write tests to not have that kind of problems.

  • @DanteMishima
    @DanteMishima Před rokem +10

    This video is a "how" not a "why"
    I get no reason why I should do this

    • @baka_baca
      @baka_baca Před rokem +5

      It's gone over pretty quick, but the reason he essentially gave was this (adding some things he missed to better highlight the overall point):
      Separate packages means that to make even a small change you need to open a new window, make the change, publish the change, then go back to your first project and install the new version once it's ready. If you're working on a team, then there's an entire extra pull request and all the delays that happen there. Your tiny 1 character change could take hours depending on how quick others are to approve the pull request. All the while, you are blocked from other work or need to install the package locally anyway to keep going...
      If you used a monorepo from the start... You'd just make your 1 character change and carry on. You might even find more meaningful changes to make for the next package version than just the 1 character change while developing if you're doing what is shown in the video.
      In other words, breaking everything into separate packages across codebases can take hours to do small changes whereas in a monorepo this happens in mere moments.

  • @a89529294
    @a89529294 Před rokem

    🤴

  • @fredericorinco9133
    @fredericorinco9133 Před rokem

    Superb acting on the + and - part. I truly believed you were capable of cocking up so badly. Have you considered Hollywood? On my way to update it to 0.0.4 to fix my apps.

  • @OfficialProjectSMP
    @OfficialProjectSMP Před rokem +9

    ... or just pin versions and test your software.

  • @0xpatrakar
    @0xpatrakar Před rokem

    Or use submodules

  • @Dampfaeus
    @Dampfaeus Před rokem

    That was a great explanation. That said, it would have been better to deploy a static .html file.
    Before anyone comments on this being a very small, non-practical example, let me just prelude that static .html files without ads also work on real projects.

  • @ordinarygg
    @ordinarygg Před rokem +1

    Awesome, first create a problem, then rollback to what worked for decades xD. JS devs are not changing)))

  • @EdwinMartin
    @EdwinMartin Před rokem

    I think many go for a monorepo only because they don’t know the npm link command.

    • @zuma206
      @zuma206 Před 3 měsíci

      but npm link only works in development

    • @EdwinMartin
      @EdwinMartin Před 3 měsíci

      @@zuma206 You don’t need npm link in production. In production you just import the packages.

  • @cruelplatypus67
    @cruelplatypus67 Před rokem +3

    Why use monorepo?
    To confuse yourself in future

  • @Yutaro-Yoshii
    @Yutaro-Yoshii Před rokem

    this is actually a solid alternative to using git submodule

  • @thekwoka4707
    @thekwoka4707 Před rokem +1

    The real nightmare here is that you're bundling esm to cjs to use in an ESM project.

  • @arekxv
    @arekxv Před rokem

    Why not just use git submodules? There is a thing already made for it. Everything is already there.

  • @mbehboodian
    @mbehboodian Před rokem

    Jason Statham?!

  • @babakfp
    @babakfp Před rokem +1

    I don't like examples that doesn't make sense :|

  • @nishantshah_
    @nishantshah_ Před měsícem

    It is june 2024, is this concept dead?

  • @45g4rerf45f45
    @45g4rerf45f45 Před rokem

    JavaScript nightmare

  • @saichand5752
    @saichand5752 Před rokem +2

    Explanation felt too quick, need to slow down maybe

  • @orenmizr
    @orenmizr Před rokem

    hi, the app now has workspace * . won't it pull the latest all the time ? what about production? no version pinning ?

  • @neil_from_future
    @neil_from_future Před rokem +1

    I'm not always watch those video because explanation felt too quick, zoom out zoom in without any word explanation where you at and why use this... But at least I have more knowledge, but not understand. This just like intro video not a "make your monkey brain understand this" type of video.

  • @StephenRayner
    @StephenRayner Před rokem

    Edit video title to how… not why. And you should consider using yarn workspaces and yarn PnP

  • @swyxTV
    @swyxTV Před rokem +5

    instructions unclear, in AMERICA we use MATH not MATHS, there is only one MATH and ours is it

    • @mattpocockuk
      @mattpocockuk Před rokem +1

      I AM WHO I AM

    • @lord_kh4n
      @lord_kh4n Před rokem

      AAUUUGGHHH

    • @baka_baca
      @baka_baca Před rokem

      Maths makes just as much sense as mathematics (which is also plural).
      In America, we kind of have a "mathematic" idea to go with our "math". As a fellow American, we might just be the weird ones here :).
      But, same same but different...

    • @Momo-vy4xw
      @Momo-vy4xw Před rokem

      My guy here must be using python_communism on a daily basis

  • @isakthehackervlogs
    @isakthehackervlogs Před rokem

    This looks like a really bad and inefficient way to do thing if I am being honest

  • @DevinRhode2
    @DevinRhode2 Před rokem

    Sorry, I really hate these 1+1 !== 2 examples. I immediately start checking out. Then, I hear about npm publish is too painful, my immediate response is, no, it's not too painful. The basis of 1 + 1 not being 2 is just not sound. Yes, give us a fictionalish example, but, I definitely don't like the 1+1 !== 2. Just one opinion tho, maybe I'm the outlier!!

    • @exactzero
      @exactzero Před rokem

      Hmm.. how about 2+2 !== 3?

    • @Dxpress_
      @Dxpress_ Před rokem

      Well, fixing the obvious "1 + 1" bug isn't the point. The point is about different ways to manage dependency versions across a repository. I.E: Multiple repositories VS. one mono-repo.
      The "1 + 1" bug is only there to serve the purpose of needing to release a new version of a project. Migrating to that new version is the actual example.
      Granted, I do feel like this video missed the point it was trying to make also. Like other comments say, it's just showing you "how" to utilize a mono-repo, not "why" you should.