Skip to content
🎓 Take the Quiz
.md

Batching

Testing each PR individually means one CI run per PR. With 10 PRs, that’s 10 CI runs. Batching groups multiple PRs into a single CI run, dramatically cutting CI cost and resource usage.

Without BatchingWith Batching
PRs44
CI runs41
Cost4x1x

✅ Pass

PR #1

Batch

PR #2

PR #3

PR #4

CI runs once

All 4 PRs merge

  1. Multiple PRs enter the queue
  2. The merge queue combines them into a single test branch
  3. CI runs once against the combined changes
  4. If it passes, all PRs merge together

If the batch fails, the merge queue needs to identify which PR caused the failure. Common strategies:

Test overlapping subsets in parallel. This allows partial merges while identifying failures.

Batch [1,2,3,4] fails
→ Test [1,2] and [1,2,3] in parallel
→ [1,2] passes → merge PR #1 and #2
→ [1,2,3] fails → PR #3 is the problem
→ Remove PR #3
→ Put PR #4 back in queue

Consider a team merging 20 PRs per day with a 30-minute CI pipeline:

  • Without batching: 20 CI runs × 30 min = 10 hours of CI time
  • With batches of 4: 5 CI runs × 30 min = 2.5 hours of CI time

That’s a 75% reduction in CI resource usage. For teams paying for CI by the minute, this directly reduces infrastructure costs.

The trade-off appears when a batch fails. If batch [1,2,3,4] fails, bisection adds 1-2 extra CI runs to isolate the culprit. But with a healthy codebase (failure rate under 5%), the savings far outweigh the occasional bisection cost.

The right batch size depends on your failure rate and CI duration:

  • Low failure rate (<2%) — larger batches (5-10 PRs) work well since bisection is rare
  • Medium failure rate (2-5%) — moderate batches (3-5 PRs) balance efficiency and recovery time
  • High failure rate (>5%) — small batches (2-3 PRs), or invest in fixing your flaky tests first

A useful rule of thumb: if bisection happens more than once per day, your batch size is too large or your test stability needs work.

SettingDescription
Batch sizeMaximum PRs per batch (e.g., 5, 10, unlimited)
Batch wait timeTime to wait for more PRs before starting CI

Batching and speculative checks are complementary strategies that can be used together:

Pros:

  • Dramatically reduces CI cost and resource usage
  • Fewer CI runs means less infrastructure load
  • Combines well with speculative checks for both speed and efficiency

Cons:

  • One failure affects the whole batch
  • Bisection adds latency when failures occur
  • May need larger CI runners for combined changes