14 ms·
Why Google Stores Billions of Lines of Code in a Single Repository (2016)
- jsnell 7y agoPrevious discussion: https://news.ycombinator.com/item?id=11991479 https://news.ycombinator.com/item?id=11991479 https://news.ycombinator.com/item?id=15889148 https://news.ycombinator.com/item?id=15889148 https://news.ycombinator.com/item?id=17605371 https://news.ycombinator.com/item?id=17605371
- svat 7y agoAlso: https://news.ycombinator.com/item?id=19303082 https://news.ycombinator.com/item?id=19303082 -- a survey of Google engineers on what they like and dislike about this.
- forwhomst 7y agoWe can just procedurally generate the comments at this point. On the one hand you need some initial comments along the lines of "I only ever use terrible tools and I just don't see how this can work" and on the other hand you reply with something like "All you need is thousands of engineers to manage the project."
- cmrdporcupine 7y agoSeems like this gets re-posted every few months. We don't actually have a single repository, although Google3/Piper really is huge and dominant. Android, Chrome, Fuchsia, and myriads of other projects don't exist in the monorepo (well, they are mirrored there) because the tooling and libraries there are really geared towards server deployment, not devices.
- melling 7y agotosh and others do a lot of reposts, Wikipedia links, etc karma farming?
- tosh 7y agostumbled upon it (again(?)) in a recent comment on "Is Git irreplaceable": https://news.ycombinator.com/item?id=21980556 https://news.ycombinator.com/item?id=21980556 and thought this might yield an interesting discussion
- Tomte 7y agoWhy does it matter to you? Does this submission hurt you?
- melling 7y agoI’m simply pointing out why we get lots of repeat submissions. Some stories are great and worth seeing every few years. Your anger gave away the fact that you do the same thing: https://news.ycombinator.com/submitted?id=Tomte https://news.ycombinator.com/submitted?id=Tomte The one downside is that it creates a lot of noise on HN. It forces new stories off the first page quicker. Also, stories about Jerry Lee Lewis’ marriage to a 13 year old isn’t HN, for example.
- Tomte 7y agoI'm not angry, actually. I just wonder why you're so invested in what I'm doing. I'm actually proud of it. More people should un-earth cool stories and submit them. About Jerry Lee Lewis: I disagree. The sheer fact that moral compasses were so wildly divergent between America and England, of all pairs of countries, so recently, is quite on-topic, in my opinion. Also, I think it's great that you found only one story you disagree with in the thirty stories my submission page shows. Clearly you approve of my selection. > I’m simply pointing out why we get lots of repeat submissions. That's explicitly okay, as the moderators point out all the time.
- melling 7y agoYou joined the conversation. I mentioned another user. I quickly looked at your account once you became indignant. I scanned your last submissions page and saw you’re karma farming too and picked out the most egregious submission. I didn’t say it wasn’t ok. I’m sure I do it occasionally. I’m waiting for the first person to write a karma farming AI. Take great stories, determine a decay time, then repost. “HN Karma Farming with Deep Learning (in Rust)”
- OzzyB 7y agoCould we have this pinned because the whole "Google uses a Monorepo and so should you" has become a huge meme and grown legs. And you're right this topic is on a circular timer.
- tosh 7y agoimho the problem space of evolution + stability of systems is becoming more zeitgeisty (more people are aware of the challenges and stumble upon monorepo as a tool to deal with this among other things) related: * unison * clojure (immutability, spec, …) * blockchain * microservice architecture
- cmrdporcupine 7y agoI mean honestly, having worked with a monorepo here, I'd definitely consider it for other places. It has advantages.
- lanstin 7y agoThe only arguments I have found against monorepo that don’t seem wrong are “the developers aren’t that good at git and can’t handle it.” Other wise it’s just making it harder to find out what code is where.
- rakoo 7y agoWell Google's monorepo is not git, and not even a "standard" one because it's not just a VCS: it's also a storage and a build infra, all in one. So while it's true that many developers wouldn't be comfortable using monorepos in git, it's not the right criticism. The real one is "there is no unified tool to do it correctly". Or at least I don't know of any.
- jefftk 7y agoAnother thing your examples of projects developed outside of the main repo have in common is that they're open source. When I was working on an open source project at Google (mod_pagespeed) we initially developed it in the main repo with exports to GitHub. Then we moved our source of truth to GitHub to make it easier to work with external contributors. (Speaking only for myself, not for Google)
- cmrdporcupine 7y agoNot all are open source, I just refrained from referring to internal projects.
- jefftk 7y agoMy understanding is that >99% of internal-only projects are in the main repo. If you think I'm missing something, perhaps write me internally (same username) and if I'm wrong I'll post here saying so?
- forwhomst 7y agoThe outcome kinda depends on how you want to count the Linux kernel.
- cmrdporcupine 7y agoAlmost everything I work on hasn't been in the main repo for the last 5 years. I work in the hardware PA, and before that Fiber. I mean, it's all mirrored _into_ there, but work happens in separate git repos, using gerrit. Prior to Fiber, yes, I worked in Google3. I've been @ Google for 8 years.
- jayd16 7y agoThat still sounds like a monorepo. Google is using external projects and has public facing projects so isn't mirroring the way you should handle it? In what way could it be more monorepo like?
- cmrdporcupine 7y agoThese projects are mirrored _into_ Google3, not the other way. And not all projects that aren't in Piper/Google3 are external facing. In fact only a minority of them are. I'm just not going to name them, for obvious reasons.
- opportune 7y agoMirroring only allows dependencies in one direction. Let's say package A is only in the monorepo and package B is mirrored into the monorepo. A can depend on some snapshot of B, (of, say, a client library) but B can't depend on packages from A, because outside of the monorepo B has no knowledge of A. Also, one main advantage of a monorepo is you can make changes across many packages at once. The canonical textbook example is changing the API of my service: I can find all the instances in the monorepo of where that API gets used and change both the API and update all the calling instances in an atomic operation. You can't (or at least, shouldn't) do that to mirrored projects because the mirror in the monorepo is downstream from the source of truth for the project.
- konschubert 7y agoIf you make backwards-incompatibilities API changes like this, you also need simultaneous/atomic deploys across all services. On the other hand, if you aren’t doing simultaneous/atomic deploys, then having a monorepo may actually be an obstruction.
- opportune 7y agoYeah, that's the part I left out because it does get complicated when it comes to releases. For simplicity's sake, let's say everything actually gets bundled into one binary and released together.
- Cyph0n 7y agoCisco uses a monorepo approach for IOS-XR. All platforms exist within the same repo, but the build system picks up only what’s needed to build the required platform’s image. Of course, the scale is much lower, since it’s a really a single OS.
- Someone 7y ago"We don't actually have a single repository” This article doesn’t claim that. Its title doesn’t imply it, and its second sentence denies it: ”today the vast majority of Google's software assets continues to be stored in a single, shared repository”
- colejohnson66 7y agoIt seems to imply it. Maybe not deliberately, but it confused me at first.
- hacker_newz 7y agoYou are being pointlessly pedantic. A lot of people still think Google has only one repo because I articles like this.
- aantix 7y agoIs it really “billions”?
- cameronbrown 7y agoYes.
- monocasa 7y agoYeah. I think it's even billions at HEAD too, not some metric about total changes.
- CydeWeys 7y agoDon't underestimate how many of these changes are entirely automated. There's a lot of versioned data and configuration stored in the monorepo, not just human-authored code commits.
- kinkrtyavimoodh 7y agoBillions is talking about LOC. As for automated changes, yes there are lots of them but from the pov of managing a VCS they are as 'legit' as manual changes.
- CydeWeys 7y agoA surprising amount of the code is autogenerated, too. Protobuf stubs, @AutoValue classes, compile-time dependency injection, etc.
- ehvatum 7y agoOne gigantic Perforce repo that achieved such Brobdingagian scale, Google had to roll their own ultra-giga Perforce that properly belongs in a hellish mondo alternate dimension of largeness. “But it’s searchable”, Google says. Yes. By the devil, it is.
- gravypod 7y agoIs writing/improving tools to fit your needs considered bad? If Google needed to store an exabyte of data into MySQL and they rewrote something with a MySQL compatible APIb (PingCap) would this have been bad?
- dahfizz 7y agoI think the sentiment is that would be solving the wrong problem. Why do they need to store so much data in a single DB, and could they use a different approach? Rewriting tools that already work well is a big of an extreme solution, but Google also has the resources to do something like that.
- joshuamorton 7y ago> Why do they need to store so much data in a single DB, and could they use a different approach? Well, we have examples of the opposite (Amazon uses a multi-repo approach) and my understanding is that it works fine, until it doesn't, when its awful. This often happens when there are security vulnerabilities, and Amazon is forced to, under time pressure, walk their entire dependency graph and pin all dependencies to newer versions, fixing forward as they go. At the point where you have a lot of code, you only really have two options.
- gravypod 7y ago> Why do they need to store so much data in a single DB, and could they use a different approach? Rewriting tools that already work well is a big of an extreme solution, but Google also has the resources to do something like that. I see the choices as: a) rewrite one core tool infrastructure component or b) rewrite everything - currently and soon to be - built on that infrastructure. It's also a question of level of abstraction. Why does my application care about database sharing, replication, leaders, followers, etc. It should only care about connecting & querying. The complications of running a system at scale should be hidden as well as possible from the code you've written. From a monorepo perspective: why do I care where my code is stored? As long as I can control visibility, hide build complexity, and expose an API to other pieces of code I have all the functionality I need. Why should the nitty gritty of a package manager, VCSs, or other multi-repo concepts influence how I write my code?
- Havoc 7y agoMore automated commits than human?
- forwhomst 7y agoThe article discusses it: "On a typical workday, they commit 16,000 changes to the codebase, and another 24,000 changes are committed by automated systems. " That was years ago though. We don't know if automated or human commits have grown faster. It also doesn't mention whether machine-assisted large-scale refactoring is counted as human or robot.
- deleted 7y ago[deleted]
- tosh 7y ago> Most notably, the model allows Google to avoid the "diamond dependency" problem (see Figure 8) that occurs when A depends on B and C, both B and C depend on D, but B requires version D.1 and C requires version D.2. In most cases it is now impossible to build A. For the base library D, it can become very difficult to release a new version without causing breakage, since all its callers must be updated at the same time. Updating is difficult when the library callers are hosted in different repositories.
- scotth 7y agoExcept they don't entirely. As soon as the monorepo interfaces with the rest of the world (like with npm packages, let's say), the problem just gets shifted onto the person trying to import/update a package. Which is further hindered by policy that discourages more than N versions of any given package. Not that I'm against the policy or how it works. It just isn't "avoided" precisely.
- tosh 7y agoI wonder how Googlers decide what ends up in the monorepo and what is outside of it. Collaborative open source outside (e.g. Android, Fuchsia, Chrome, …)?
- scotth 7y agoIt's often the product team's decision. Anybody can spin up a Git repo when they need one. There's freedom there, but you miss out on a lot of tooling and healthy discipline by doing so. Once you're in the mono repo, you have to play by its rules (well...should anyway). Like in the case of npm packages I mentioned above.
- tosh 7y agoThanks for the context!
- umanwizard 7y agoPresumably google doesn’t use npm or other external package managers that download random things from the internet. Why would they?
- tomrod 7y agoNaive question Can't we call Github a monorepository, as it is a single area one can use to access code? Implementation details likely differ from whatever Google and her engineers are cooking up, but at the end of the day I point to an archive and pull artifacts. Certainly not every Googler clones the entire monorepo...
- alexhutcheson 7y agoGitHub isn't a monorepo because you can't change multiple projects with a single commit. In a monorepo you can do things like change a function signature and change all of its callers in one commit, without breaking anyone's build. If the implementation and its callers live in different projects within GitHub, then you can't do this safely, and you need to do more work to provide backward- and forward-compatibility in your changes.
- CydeWeys 7y agoThis is very important. When you're developing a large monorepo like Google3 you frequently get large scale changes from engineers outside your team, doing exactly these kinds of large scale reactors. It puts the onus of fixing things on the people making changes in the widely used libraries rather than separately on all the individual library users, which is great. It's way more efficient to have one person who knows exactly what's changing go fix it everywhere than require dozens or more separate engineers to have to investigate some new incompatibility and then potentially resolve it in sub-optimal ways.
- juiyout 7y agoIn your example (change a function signature and change all of its callers in one commit), would it require code reviews and approvals from every affected projects?
- alexhutcheson 7y agoYes, although if you can prove convincingly that it's a 100% safe change you can often get approval from someone who has approval power for most of the repository. In practice, if you're changing 100+ individual callsites, then you would probably make a backwards-compatible change, then use an automated system to send out and manage a bunch of different commits to clean up call sites, then clean up your old function signature once all the commits are submitted. If your code isn't a really widely used library then you probably have fewer than 20 callsites, though, so it's nice to be able to do it in one commit.
- jayd16 7y agoMonorepos are cool but I hate perforce with a passion. How can we use git? A lot of work is going into making git scale better which is nice but there will always be small open source repos. You could mirror them but it seems like it would be nice to not have to do that. Is there any research going into figuring out how to keep many repos in sync with a single commit? Maybe you could use submodules across your company...have a single master repo that essentially just keeps track of working version sets. That might work but it sounds torturous. Is anything on the horizon to solve this problem with git?
- forwhomst 7y agoWhy do you dislike perforce? I’ve used them all and git is the worst, in my opinion, of the ones that aren’t dead and buried (like cvs). Perforce is my fave. Internal research at google suggested that ‘git5’ users were objectively less productive than average, but there’s some friction around ‘git5’ so that doesn’t necessarily implicate git itself.
- jayd16 7y agoI mostly dislike the general bugginess, the need to use plugins of varying quality in all your tools, the centralized design and/or poor dvcs support, and the strange feature dead zones you get. As far as I can tell (and I opened a ticket but maybe I pulled a bad support tech) it's impossible to see what CLs were merged into a branch, only what still needs to be merged. The general low quality of a lot of the Perforce tools has me scratching my head every day. How hard is it to make a log window that scrolls to the bottom? The p4proxy doesn't have a max size, you need to manually delete files on the machine to free space!?
- forwhomst 7y agoYou can definitely inspect the changes that have been integrated into a perforce branch with filelog and changes, it's not worth pointing out exactly how, you can find examples online (much like git). And if you don't like how p4proxy behaves when it runs out of space, just wait until you experience git with a full disk.
- Speakeasys 7y agoI can only imagine how long ‘git status’ takes to complete
- jsw 7y agoI've always been curious about the general directory structure they use for this. Does anyone have insight?
- forwhomst 7y agoIf you want the gist of it just look at any project that has been exported from Google internals to github, I'll point to the moderately sized https://github.com/google/certificate-transparency/tree/master/cpp https://github.com/google/certificate-transparency/tree/mast... It's obviously a microcosm but having base, util, net and some directories for each project is pretty much how it goes.
- username90 7y agoTop level directories by product area, then team/project based sub directories most of which would be their own repositories if you didn't do a monorepo. There are more exceptions to this than can fit in a post, but that is the general structure.
- mlthoughts2018 7y ago“It was a Perforce accident that didn’t scale and later got retrofitted with mythology about monorepo designs.”
- sabujp 7y agowe're going to make this scale even more
- Waterluvian 7y agoIs a monorepo more than just semantics? At that scale I need tools to manage the monorepo. What about making tools to manage many repos together?
- didibus 7y agoYou should take a look at: https://github.com/mateodelnorte/meta https://github.com/mateodelnorte/meta
- tomasGiden 7y agoEricsson has another philosophy where there connect multiple repos at ci/cd-time. They have open sourced a tool for that called Eiffel [1]. There is also a book [2] written by the author of Eiffel that is quite good. One of his argument is that when, as an enterprise, you buy a company with a big mature code base, you can’t just move it into another common repo with all custom tooling (also very anti agile to force everyone into the same suit). A big difference though might be that Ericsson deals with a lot of custom hardware for telecom networks. So their ci tooling might be more complex than google’s. Also, continuous deployment is not really an option for them. Then it is better to just have each piece sent out events on what’s happening (builds, test runs etc) and let event listeners in other parts of the ci/cd pipeline work out what to do. (I have worked for Ericsson previously for 7 years but that was before Eiffel) [1] https://eiffel-community.github.io/ https://eiffel-community.github.io/ [2] https://www.amazon.com/Continuous-Practices-Strategic-Accelerating-Production-ebook/dp/B07HJJN6S9 https://www.amazon.com/Continuous-Practices-Strategic-Accele...
- dehrmann 7y agoPosting these because I don't see them mentioned so often in the mono/polyrepo debate. Choosing a monorepo? Be prepared for: - Investing in the build system - Investing in CI/CD - More painful upstream dependency management - A serious investment in architecting modules and thoughtful dependencies - Issues because of a bad deployment sequence - Slow version control Polyrepo your thing? - Managing your own artifact repo (pypi, artifactory, etc) - Painful cross-project changes - Repeated effort around builds
- twblalock 7y agoDon't try a monorepo unless you have a team of engineers who can work full time on maintaining the build tooling, enforcing good practices, and training the rest of the engineers on how to behave in a monorepo.
- forwhomst 7y agoIf your organization lacks the ability to enforce good practices, train engineers how to behave, and otherwise acculturate people to your ways then there is no particular style of repo that can save you from failure.
- vbezhenar 7y agoI work in a tiny team (basically 2 people), but we have to work on multiple small projects (around 200k LoC total) including few shared libraries on Java. We used different repositories before with all releasing rituals, etc. But I tried monorepo and "all use latest" and it worked surprisingly awesome for us. Changes across repositories are much easier to do than before.
- twblalock 7y agoA team of two people can work with pretty much anything. The hard part is figuring out how to work with 100 or 1000 software engineers who all commit to the same repo.
- vanniv 7y agoIndeed, maintaining the greenness of the build in a giant monorepo is extremely expensive. It isn't clear to me that it is worth the investment, even for Google -- though it clearly world's "well enough"
- m0zg 7y agoIt's only expensive if you don't have tests and CI. If you do have tests and CI, it's much cheaper to maintain one repo than three dozen smaller ones: garbage simply can't get into master. Note also, that if you want to ship high quality software, having a fragmented repo doesn't free you from the need to have tests and CI, if anything it leads to duplication of effort.
- discordance 7y agoHow do they avoided leaks? - surely having a giant mono repo poses an access risk
- atesti 7y agoI don't remember where I read or heard this, but if you try to download all the source code at once, they will probably block your account
- fizixer 7y agoIf you're a type 0 company [1] and you have a billion lines of code, much less multiple billions, you're most likely sitting on massive amounts of code bloat. [1] https://en.wikipedia.org/wiki/Kardashev_scale https://en.wikipedia.org/wiki/Kardashev_scale
- w0mbat 7y agoIn the 90s, a startup called WebTV managed to negotiate and buy a perpetual SOURCE CODE license for Perforce (P4). WebTV built their own good version control system called "SourceDepot" on top of P4. When Microsoft bought WebTV they got this license, which enabled them to cheaply roll out P4/SourceDepot to massive teams for whom it was a big improvement over what they had been using. With access to the source, they could modify it to their needs and scale away. Google tried to buy a source license early on, but Perforce had learned their lesson from what happened with WebTV and wouldn't sell them one. That's how Google ended up doing elaborate projects for years to prop up and eventually replace P4. Source : I worked at WebTV, Microsoft and Google.