Trunk-Based Development at Facebook
An analysis of the style of Trunk-based Development that Facebook uses as well as some of the elements that make it an effective development practice.
Join the DZone community and get the full member experience.Join For Free
tech crunch has an article called the next 6 months worth of features are in facebook’s code right now, but we can’t see . that’s a great title. never mind that the article is nearly two years old. linked to it is a 52-minute video that should be mandatory for all developers and their management to watch, even if after watching it they decide to not do the same. it’s all about toggles, trunk based development (tbd) and branch by abstraction. facebook’s chuck rossi talks us through the contract and understanding between developers and release engineers concerning releases.
facebook release/change wisdom
all quotes from the video:
“the business requires change … yet change is the cause of most problems”
“we have two options: we can discourage change in the interests of stability, or we can allow change to happen as often as it needs to."
“lowering the risk of change via tools and culture”
how i interpret what they do
here is a branch diagram for just over a week at facebook. it’s my guess of course:
= a branch as it’s made
= a merge (cherry-pick)
here’s a screen-cap for their description of the pushes:
it is from that, and the accompanying talk, that i’ve made my version of the branch diagram.
the importance of cherry-picks
four (our numbers are contrived) red commits ( ) are merged to the main tuesday release – these constitute “production hardening”. they were cherry picked, meaning other commits are left on trunk. three blue commits made it to the weds release, via a cherry-pick merge. similarly two purple ones are for the wednesday release, and one brown one for the friday release. saturday and sunday have no planned releases. sunday, however, it all starts again as a new release branch is cut. there’s also that monday release (the last one on the old branch), that has the fewest possible commits cherry-pick merged to it. one presumes that they can skip releases if there’s nothing to go out.
note the merge directions
things happen on trunk and get merged to a release branch, if they get merged at all. things can be regular enhancements, or can be defect fixes.
one might think that defects should be fixed on the release branch and merged back to the trunk. that should only be the case if it is impossible to reproduce the same bug on the trunk. the reason you want to do it the way shown, is that you want zero regressions. regressions can’t happen if the change is made on the trunk then cherry-picked to a release branch.
inevitability of release
if you’re a developer and you’ve committed and pushed to the trunk, your stuff is going to go live in at maximum seven days. you don’t have to nurse things through the merge-to-release branch workflow; you can just wait for it to go live anyway.
not illustrated in the branch diagram
culture and developer responsibility
developers don’t break the build when they commit to trunk. if they do, they are automatically rolled back. they can fix the mess in their own time. to achieve this facebook will have a serious continuous integration infrastructure.
if you didn’t watch the video, you need to know that developers have to stick around in irc for the merge moments. that is following their declaration of intent for their commits to be cherry-picked into the existing release branch. this is a facebook rule, and other companies doing tbd might not do the same. indeed for others it might be release engineers doing merges, and based on an known list that will essentially patch a release branch, that was not expected to have a point release. it’s that facebook kinda know in advance they have enough for releases on weds through to the last release of the old branch on monday.
facebook calls these gatekeepers (22 mins into the video)
if you’re working on something and it’s not ready to go out yet, then you’ll be wrapping the ui and logic in a ‘feature toggle’. it could be that the release engineers will toggle things on or off themselves, especially if marketing are driving the release moments. as likely is the scenario that you’re going to need another week or two to complete the mini-project.
this and the implicit branch by abstraction for code that is replacing the previous implementation of something, mean you’ve avoided a feature branch that has a nebulous cost.
they also have the ability within one released version to set percentages of the public that can see a feature. toggles are not just two-state for facebook.
Published at DZone with permission of Paul Hammant, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
Effective Java Collection Framework: Best Practices and Tips
Microservices With Apache Camel and Quarkus
Avoiding Pitfalls With Java Optional: Common Mistakes and How To Fix Them [Video]
How To Approach Java, Databases, and SQL [Video]