Back to all posts

A Better Way To Merge

By Eli SchleiferJune 29, 2022
Merge Queue

The fastest engineering team, and the one where you are always right 😉, is the team of one. To the great consternation of many engineers, there is only so much code a single person can manage to sling, and this means that you need to work with others.

With great team size comes great opportunities (for miscommunication, crosstalk, and conflicting changes)

The most successful software engineering organizations succeed because they constantly invest in systems to support building software at scale. We started trunk to bring that in-house DevEx (developer experience) might to everyone.

UberAirbnb, Twitter, Shopify, Robinhood, and many others have built sophisticated in-house merge queues to unlock efficiencies and protect against broken builds. Until now, there weren’t any good options to get this superior workflow besides dedicating a team to build your own, but now there is: Trunk Merge.

Today we are announcing the public availability of Trunk Merge (docs). It is our take on a merge queue, which every team >10 engineers should be looking to add to their workflow.

What is a Merge Queue?

A Merge Queue is a service in the loop that, as it sounds, coordinates the merging of code onto a protected branch (usually main or master) ensuring that multiple pull requests from contributors do not run into logical conflict with each other.

Keeping your main branch green

A merge queue’s primary job is keeping your main(or other critical, protected branches) green. A quick google search will turn up a cornucopia of memes about breaking the build.

Before automated testing solutions, keeping your mainbranch green could literally be as simple as ensuring no compilation errors were introduced into the code base. While automated testing has greatly increased engineering velocity and efficiency, it also led to an explosion in the amount of code that must be coordinated to keep the main branch in working order.

Perversely, a broken test can often live in a codebase a lot longer than a broken compilation unit because it is often undetected; that is until an engineer attempts to land a new pull request that triggers the broken/flakey test. This can lead to a lot of hand-wringing as the engineer tries to determine why a test in a seemingly untouched piece of the code is now failing.

Why are automated builds and tests not enough?

The layers of unit and integration tests that are used to protect modern repositories are insufficient to protect the main branch without a service in the loop. Fundamentally, the problem relates to the staleness of CI results.

In geekspeak, we say that a pull request is ready to merge when “CI is green”; meaning all gating tests are passing and the code reviewer(s) have signed off. In an active repository, a green CI result is insufficient because it is always subject to staleness. Relying on stale CI results can lead to logical merge conflicts and broken builds.

As the HEAD of the main branch in an active repository is constantly moving, the CI results are constantly going stale. A merge queue, inserted into the loop, ensures that the CI results are always fresh.

Not just better merging, but a better workflow

Engineers, like all humans, are terrible at multitasking, and babysitting a pull request until it merges onto the main branch is often a blocker before an engineer can proceed with her next work item. With Trunk Mergewe’ve made it possible for engineers to signal the desire to merge and allow the service to handle the details. An engineer can open a pull request, mark it ready to merge, and let the service do the rest.

This means instead of waiting for all workflow rules to be green and then having to go click the “green button,” we’ll press the button for you (figuratively). With Trunk Merge engineers are able to queue a PR by leaving a comment on the pull request “/trunk merge”, or using the trunk command-line tool.

Queue Management

Occasionally you’ll encounter a fire and find yourself in a need to land code as fast as possible in order to unblock other developers, or even in need of pausing merging code altogether. With Trunk Merge, you get advanced controls over pausing, resuming, prioritizing submissions, and evicting submissions. These controls are all restricted to admins and can be used via the trunk cli.

Resources

Everything we make at Trunk is free for public repos at any scale and private repos with up to 5 committers.

Try it yourself or
request a demo

Get started for free

Try it yourself or
Request a Demo

Free for first 5 users