Google's Scaled Trunk Based Development
Join the DZone community and get the full member experience.Join For Free
google’s published talks
my knowledge about how google developed software ended in 2009. they've talked publicly a number of times on the topic, though:
- pat copeland: google’s innovation factory and how testing adapts (apr 2010)
- ashish kumar: development at google (dec 2010)
- nathan york: tools for continuous integration at google scale (jan 2011)
- michael barnathan, greg estren & pepper lebeck-jobe building software at google scale tech talk (mar 2012). these guys go deeply into the directed graph nature of builds
- john micco: tools for continuous integration at google scale (aug 2012)
- ari shamash at gtac 2013: evolution from quality assurance to test engineering . ari goes further than ashish and the others into the “test engineering” excellence his team does and why that’s a formal group beyond devops.
all these videos are great. there’s so much to see in them, particularly the slides with charts. there’s also a blog dedicated to their devops:
- john thomas and ashish kumar: welcome to the google engineering tools blog!
trunk based development
in the materials above, these googlers talked about working on head , and that checkins happen to head at all times. ashish says trunk a few times towards the end in a q&a section, and he does mention an avoidance of branching for ongoing development (nothing to do with releases per se). so it’s official, trunk based development ( tbd ) is what google do, and boy do they scale it!
things specific to google
(from john micco’s 2012 talk)
a shared supercomputer for compilation
note: effectively a shared supercomputer!
google have a lot of tooling for individual developers at the workstations, validations that somethings ready to commit (integrate into shared trunk), and the formal integration/merge/commit itself (because some time may have elapsed since that prior validation).
they have a “distributed builds” capability that’s shared by all of those. in layman’s terms it is effectively a supercomputer for the compilation (and unit-test execution) phases. it features and “object cache” and an “action cache” that can leverage someone else previously doing the same thing(s) so that results of the build are pulled in quicker. time is saved for the developer in question, but they are also able to calculate a saving in terms of execution cost ( cpu seconds for one).
ashish talks of teams needing to depend on a common thing – socket. let’s call it s0ck3t so we think of it as a module rather than a concept . two different developers in two different teams (say gmail, and googlecheckout) have dissimilar technologies, but at the lower level have shared services. in our hypothetical example they both depend on s0ck3t. for their work in progress, neither developer has actually made modifications to s0ck3t. it is just in their directed graph of things they need to build and test before they can run the app (or commit the change). if one developer has build s0ck3t for the trunk at revision #12345 and the other developer minutes or hours later needs to do the same, then the supercomputer can do an optimization and give him/her build results (including object code) from the earlier build.
avoidance of ‘clean’
ari mentions in his talk that the whole system is designed to build incrementally, and not require ‘clean’ at any stage. provable directed graphs of things that should consequentially be rebuilt, are needed for that. their source setup makes that doable. for the rest of us in maven land (or equivalent), there are moments when you’re driven to do ‘mvn clean install’ by superstition more than necessity. in many of the talks above, the avoidance of ‘clean’ is cited as a guiding rationale for the custom tooling google have done.
huge tooling around pre-commit goodness
mondrian is what google use for code reviews internally. here is a 2006 article on that. at least it was in use at the start of 2009. many other aspects of their pre-commit tooling have been discussed, but this is the key piece. as you ‘pre-submit’ a perforce change list for review, a daemon side of mondrian kicks in and takes your pending change list and runs it through multiple tests, adding more data to the mondrian code review for that change. this is all available to the developer before they go as far to submit something for review, which is good as most people like to fail in private.
if someone were to change s0ck3t on its own in a change-list and push that into mondrian for review, the consequential build would pull in all that could be impacted from the entire trunk. that could be many hundred of other modules for a huge range of site/apps that could have different release schedules. it does not matter when the release would go out for those individual pieces. we want to know about the potential breakage right now. jez humble reminds me that ci is about earliest possible integration news, and that trunk is the best foundation to deliver that. i can’t remember how enthusiastic notifications of breakages were, for impacted downstream modules broken in a single commit – imagine emails being sent 300 other teams: “footle tried to break adsense with commit #13456”. without one trunk for each module (or worse), you’d need to depend on recently binary artifacts for the same directed graph traversal, and it would be infinitely harder to guard against false-negative and false-positives. google know exactly what they are doing with “all build from source every time, in one trunk”.
humans in the workflow at the pre-commit stage
there are armies of people willing to do code reviews. these developers, however, have regular teamwork to get on with, and reviewing code could be seen to detract from that. it is in their culture to code review though. not just things that are happening to the code you’re assigned to nurture, but to arbitrary bits of the system. again, mondrian is the starting and ending point for this.
both the videos about show much data analysis of commits, attempt to commit, builds, breakages, remediation (etc). google knows how much it can save for identified problems, and can work out if it is cost-justifiable to develop something for that.
in many companies, good ideas might not get past managers, even with accompanying cost-justification. that’s not a problem in google as developers have 20% time, meaning they can try something for the benefit of the company without the formal approval gates needed for a funded effort. there are well known apps like gmail, gtalk, google news and adsense coming out of 20% time, but there’s as much if not more coming that are not products/apps/services as such, but do improve developer throughput in tangible ways. in that way, an improvement to tooling could go on to get formal budget after it has become successful.
let’s talk about s0ck3t again. there’s a directory in the trunk for it’s code and tests. it has an small team that looks after it, and are the notional owners of it. one would hope it is stable, and that the team in question looks after many similar pieces. either way, developers can make a change to any of the source files in s0ck3t, while doing work that has business value. they need the explicit authorization of the one of the owners of the module to get that commit in. mondrian serves as the place that happens. while it is working out if there is sufficient karma for the commit proceed, it takes into account the contents of the owners file. owners files are in the module’s directory and under source-control of course. though the owners file is visible to all, only their owners can change them (or the perforce administrators).
in common with other tbd companies
there are more than these two aspects that they have in commit with other trunk based development teams, but these were the two mentioned in the talk:
committing to anything
they have pulled back from “common code ownership” an use the owners files mentioned above. mondrian and tooling are an effective guard against commits that are not right. there is the potential for anyone to commit to anything though. there’s no officiousness around processing the submissions: “ you should not commit to this at all” is not the attitude the reviewers, while there may be criticism of the actual content of the change list.
diamond dependency worries
ashish mentions guice at the end of his talk (54.5 mins). the jar is centrally available (not disclosed how) to all things in the trunk that depended on it. they can only have one version of guice for everything in the entire trunk. for example gmail and googlecheckout are not allowed to depend on different versions in trunk (don’t know if they do or don’t). the reality of different release schedules are that different versions of guice could concurrently be in production, but that’s different. thus, a single change-list would upgrade guice for everyone, and there would be no broken build in any way afterwards. interestingly guice was made by googlers, but is open source so is treated as “third party”, unlike the s0ck3t we talk of that could be open source (i guess), but is not, and is therefore in the trunk as source.
merge conflicts rare (q&a at the end of ashish’s presentation). merging to working copy is, of course, the merge individual developers typically encounter for tbd . if you have kept abreast, it is typically painless as ashish mentions. if someone were to rename a whole directory (an example of one type of refactoring), then “merge-through-rename” is the feature of the source control package you really want.
ashish mentions in his talk (52 mins in) that releases are made from branches cut from the trunk, and that cherry picks may happen after that (to production harden the release). obviously each product team maintains it’s own release schedule.
biggest perforce repo
google’s perforce usage is apparently the largest single repository worldwide. in other words, the worlds biggest trunk. i’d like to know how many gigabytes that is for head of everything.
ashish talks of an intention to open-source their build language. i’ve not seen it yet, and googlesearch isn’t finding it for me. here was a quote from ashish on open sourcing the build language:
“make and others are extremely restrictive/problematic as the dependency information is not exact in those … the more exact you can get, the more hermetic your build therefore you can paralelnize and distribute; so we would like to contribute that back”.
twenty one minutes in to the excellent barnathan/estren/lebeck-jobe tech talk there’s a glimpse of the build language.
some years ago, the selenium2 team gravitated around crazyfun which is highly reminiscent of the build language google used internally (more later).
a few more words on facebook
i’ve blogged twice on tbd at facebook this year. simon stewart (ex thoughtworks, ex google) talks some more about facebook in his presentation some hours after ari’s one on test engineering at gtac . to see his section of the first video: fast forward the slider to 7 hours, 17 minutes. facebook have one trunk for ‘www’, one for android and one for ios apps (video: 8h:01m). whereas the www trunk was subversion (last i heard), the android one is in git and has a worflow that includes a ‘master’ and ‘stable’ branch. if they are sharing code between ios, android, and www they are implicitly doing so in a way other that a relative source directory.
directly after that simon is asked as closing question ( noah sussman ): “… so why no pre-commit hook?”, and simon answered “because we have not had the need for it”. there’s an implicit ‘yet’ in that language, that he goes on to elaborate before closing. smaller agile teams too, will try tbd without too much pre-commit tooling, and use continuous integration & speedy rollback as the safety net, as well developer promise to do the right thing before committing.
buck was mentioned too in simon’s gtac presentation (at the 7h 33m mark). it is a build technology they’ve launched that also works well for tbd teams: http://facebook.github.io/buck and like google’s unreleased one was felt to be advantageous over existing open-source technologies. it is similar in design to crazyfun as mentioned above.
Published at DZone with permission of Paul Hammant, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.