Skip to content
.md

What is a Merge Queue?

A merge queue sits between “PR approved” and “PR merged.” It validates changes before they land on main.

Simple merge queues serialize merges. Modern ones do more: test PRs against future main state, batch PRs together, run dedicated CI, and parallelize testing across independent code paths.

Without a merge queue, two PRs can each pass CI individually, yet break main when combined. Each PR is tested against an outdated snapshot of main—not against each other.

This happens constantly: renamed modules, deleted functions, changed signatures, conflicting config changes. No merge conflict, but broken code.

The Paradigm Shift: CI Before Merge, Not After

Section titled “The Paradigm Shift: CI Before Merge, Not After”

A merge queue tests each PR against its actual merge target—including all PRs ahead of it. The key insight: test the PR against what main will look like after the merge, not what it looked like when the PR was created.

Traditional workflows run final CI after merging to main:

Traditional: CI After Merge

Pass

Fail

PR CI ✅

✅ Merge to Main

CI on Main

Deploy ✅

🔥 Main is Broken

All devs blocked

New PRs inherit breakage

Someone must fix it

Everyone rebases

Might break main again...

The problem: by the time you discover the failure, main is already broken. The damage cascades:

  1. Deployments stop - you can’t ship until main is fixed
  2. All developers are blocked - no one can merge until the fix lands
  3. New PRs inherit the breakage - any PR based on broken main will also fail CI
  4. Everyone must rebase - after the fix, every in-flight PR needs to rebase
  5. The cycle can repeat - rebasing and re-merging might break main again

A merge queue flips this: final CI runs before the merge:

Merge Queue: CI Before Merge

Pass

Fail

PR CI ✅

Enter Queue

Queue CI: test PR + main

✅ Merge to Main

PR rejected (main untouched)

Main is green. Deploy anytime ✅

Only this PR author needs to fix

The queue tests the PR as if it were already merged with current main. Pass? Merge succeeds. Fail? PR rejected, main untouched.

This means:

  • Main stays green — broken code never lands
  • Deploy anytime — main is always releasable
  • Failures stay contained — only the PR author fixes their code

A merge queue makes “broken main” impossible by construction.

Modern merge queues offer more than serialization:

A merge queue does more than automate merges. It:

  1. Keeps main stable by testing PRs against their actual merge target
  2. Validates before merging — CI runs before code lands, not after
  3. Increases throughput through batching, speculation, and parallelism
  4. Scales to large codebases with selective testing
  5. Handles exceptions with priority queues

Next: How merge queues work covers the mechanics.