WarpBuild LogoWarpBuild

Scheduling millions of CI jobs across diverse infra

By Darshan Chaudhary · Published · Updated

How we schedule CI jobs across bare metal, Macs, and customers' own clouds

Scheduling millions of CI jobs across diverse infra cover

WarpBuild offers managed self-hosted runners for GitHub Actions, among many other features. Every CI job gets a fresh ephemeral VM that boots, runs one job, and is destroyed. On a typical weekday, we run millions of these jobs across our bare-metal instances and Apple silicon Macs, and in our customers' own AWS, GCP, and Azure accounts.

Our infra is quite diverse, spread across different geographies and infra providers. In this post, we will talk about the recent changes we made to streamline the operations and give us a better handle on this infra.

CI jobs per day from last 6 months, one bar per day
Fig 1: CI jobs per day in the last 6 months

Placing a job

When a job comes in, we have to place it on a particular node. There are two aspects of scheduling that job:

  1. Which pool of machines should this job run on?
    • This is routing: turning the job's runs-on label into a priority-ordered list of infra pools.
  2. Which exact machine in that pool of machines should take this job?
    • This is placement: which host in that infra pool has room for the VM.

Where we started from

We have two bare-metal fleets for our customer jobs: a Mac fleet for macOS jobs, and a Linux fleet.

Originally, our Linux fleet was present in a single data center. VMs ran as Kubernetes pods via KubeVirt. There were various limitations with this setup, which we wanted to fix:

  1. We wanted the scheduler to be a thin, standalone component that only places VMs on nodes, and we used few of Kubernetes' other features anyway.
  2. VMs were capped at 30 vCPU, so our 32x jobs always fell back to our backup infra stack, even though bare-metal instances have better per-core and disk performance.
  3. We were scheduling our Mac fleet via Nomad, and managing two different schedulers was an operational overhead.
  4. There were also reliability issues:
    • VMs would get stuck booting
    • the per-node cap on runner pods, which avoids noisy neighbors since all VMs on a node share its network and disk bandwidth, was not enforced
    • long tail latency on scheduling decisions

Moving to Nomad

We decided to consolidate both our fleets under a single Nomad 2.0 control plane and make it extensible, so that when we add new data centers and infra providers in the future, we can manage the complexity.

One Nomad control plane schedules both fleets: the backend sends each VM to the Nomad servers as a job, Linux and Mac hosts dial in to them over mTLS, and VMs on the backup infra stack are launched by the backend directly, outside Nomad
Fig 2: One Nomad control plane

The control plane runs Nomad servers in an HA configuration, using binpack scoring, with preemption disabled, and a Raft write-ahead log. All Linux clients and Mac clients (both in their separate node pools) dial in to the servers over mTLS through a network load balancer. Nothing dials out to a node, which keeps networking simple across multiple providers over the public internet.

On Nomad, the backend registers one batch job per VM. Nomad runs an evaluation, picks a node, and creates an allocation. A trimmed Linux 4x job spec looks like this:

job "<runner-id>" {
  type        = "batch"
  datacenters = ["*"]

  constraint { attribute = "${meta.arch}"                 value = "amd64" }
  constraint { attribute = "${meta.os_family}"            value = "linux" }
  constraint { attribute = "${meta.warpbuild.com.status}" value = "ready" }
  constraint { attribute = "${meta.linux}"                value = "ok" }

  affinity   { attribute = "${attr.kernel.name}" value = "linux" weight = 1 }

  group "vm" {
    disconnect { lost_after = "8h"  replace = false }
    reschedule { attempts = 0 }
    restart    { attempts = 0  mode = "fail" }

    task "launch-vm" {
      driver = "raw_exec"
      resources {
        cores  = 2
        memory = 16384
      }
    }
  }
}

We use two Nomad primitives to control where allocations land:

  1. Constraints - these are hard constraints, and a node that fails one is never considered for the job.

    • regions - continent, country, plus datacenter globs
    • health - warpbuild.com.status = ready
    • capability - linux = ok, macos = ok, plus per-image readiness labels
  2. Affinities - a weighted preference added to a node's score.

    • Mac chip generation - M5 Pro > M4 Pro > M2 Pro, so newer chips take traffic first while older Macs still absorb overflow
    • infra provider - provider weights inside a single pool.

Since Nomad is used as a thin scheduler, restart, reschedule, and disconnect.replace are all disabled. Nomad never restarts a failed VM or launches a duplicate if a node temporarily loses contact with the servers. Handling failed or stuck VMs, including retries, stays in the backend.

Two VMs per Mac

Apple's license and Virtualization.framework allow at most two macOS VMs per physical Mac. Our Mac runner sizes are 6x and 12x, and a 12x should fill a Mac on its own.

Nomad has no native way to express "at most two 6x VMs or one 12x VM". Instead, we assign each Mac a synthetic cpu_total_compute budget during setup based on the processor:

  • M5 Pro: 15000 MHz
  • M4 Pro: 14000 MHz
  • M2 Pro: 13000 MHz

Each Mac job books 1000 MHz per vCPU (6000 for 6x, 12000 for 12x), giving us the semantics we want. The same packing rules hold across all three chip generations using standard Nomad resource accounting.

When the primary infra stack is full

When Nomad is not able to schedule a job because the bare-metal fleet, our primary infra stack, is full, that job and all other jobs of that size or bigger move to the backup infra stack for the next 30 seconds. We do not track free bare-metal capacity in the backend; instead, we let Nomad say no and react to it, since its placement check already accounts for fragmentation, whole-core cpusets, constraints, node_max_allocs, etc.

Concretely, the spill path works like this:

  1. The backend registers the Nomad job. If no host has room, Nomad emits a blocked Evaluation event.
  2. An event forwarder sidecar streams /v1/event/stream?topic=Evaluation and POSTs failed runner evaluations to a backend webhook, which updates its metadata store for the runner pool with a TTL of 30 seconds.
  3. In parallel, the event is queued for the fallback consumer. If the org has a fallback pool, the consumer purges the queued Nomad job and re-allocates the job on the fallback infra pool.
A failed placement marks bare metal full for 30 s: Nomad finds no host with room for an 8 vCPU VM, the event forwarder reports the blocked evaluation to the backend, which marks bare metal full for 8 vCPU and up in its metadata store and re-allocates the job on the fallback pool, the backup infra stack
Fig 3: A failed placement marks bare metal full

For Macs, there is no backup infra stack to fall back to, so we ensure fair usage via resource quotas instead. They are enforced in the backend before Nomad sees the job. We sum vCPU across all the runners per org, and enforce each org's vCPU ceiling.

Onboarding new providers

Once our scheduling was consolidated with Nomad, we were ready to onboard new infra providers in earnest, and new problems showed up just as quickly.

Due to the diverse nature of our infra, there were many minor differences in the network setup, memory, and hardware across providers, and tuning them was a continuous process in the early onboarding days:

  • During the initial Linux cutover, a misconfiguration in the network setup broke IPv6; we shifted traffic back to KubeVirt, fixed the issue, and moved back to Nomad within two hours.
  • Two days later, ~10% of Linux x64 jobs started hitting random errors, slow boots, and disk corruption. The root cause turned out to be a single host with non-ECC DDR5 silently corrupting memory and failing every job that landed on it. That led us to build a periodic check that detects a bad host, cordons it, and alerts.
  • On another provider, faulty switch ports started dropping packets, and we needed to move affected workloads off that infra until it was fixed by the hardware provider.

These incidents pushed us to invest in building capability which would allow us to move customer workloads between infra pools dynamically as a data change, without needing a code change or deploy.

Routing tree

We wanted to be able to specify at an arbitrary level of precision where a particular workload for a particular customer should land.

Our input per job is the runs-on label. It has the format:

warp-{os}-{version}-{arch}-{size}[-{qualifier}]

We first tokenized the label:

LabelTokens
warp-ubuntu-2404-x64-4xubuntu 2404 x64 4x
warp-ubuntu-2604-arm64-6x-xfastubuntu 2604 arm64 6x xfast
warp-macos-15-arm64-6xmacos 15 arm64 6x

Then, we created a routing tree where each key is a token, and the value can be a leaf or another JSON object. The leaf value is a list of infra pools where the job must be placed, in that preference order.

{
  "default": ["bare metal Ashburn", "backup infra stack"],
  "ubuntu": {
    "2204": { "arm64": ["backup infra stack"] },
    "2404": { "arm64": ["backup infra stack"] },
    "2604": {
      "arm64": {
        "default": ["backup infra stack"],
        "6x": { "xfast": ["Mac fleet Dublin"] },
        "12x": { "xfast": ["Mac fleet Atlanta"] }
      }
    }
  },
  "windows": ["backup infra stack"],
  "macos": ["Mac fleet Las Vegas"]
}

There is also a special key default. To route a job, we walk down the tree one token at a time, remembering the deepest default we have passed. The walk stops at a leaf and returns its list; if it hits a token with no matching key, or runs out of tokens, it returns the deepest default it passed.

For example, ubuntu 2404 x64 4x goes down ubuntu and 2404, finds no x64 key, and gets the root default: bare metal Ashburn, then the backup infra stack.

InteractiveWalking the routing tree
runs-on
osversionarchsizequalifier
root
default1bare metal Ashburn2backup infra stack
ubuntu
2204
arm64backup infra stack
2404
arm64backup infra stack
2604
arm64
defaultbackup infra stack
6x
xfastMac fleet Dublin
12x
xfastMac fleet Atlanta
windowsbackup infra stack
macosMac fleet Las Vegas
x64

Routes to bare metal Ashburn, then backup infra stack. There is no x64 key under 2404, so the walk stops, and the deepest default it passed wins: the root's default. The backup infra stack is used only while bare metal is full.

Fig 4: Walking the routing tree

The order of the list is the preference, and the backend tries the infra pools in that order.

Per-org patches and versioning

These routing trees are per org and per product: CI runners, Docker builders, WarpBuild cache, telemetry, and agent runners each get their own routing tree. Rather than copying the full JSON tree for every org, each org's effective tree is built from two layers:

  1. Regional base trees (default, US, EU) shipped as config. The backend loads and validates every base tree at boot, refusing to start if any entry references a missing infra pool ID.
  2. A per-org RFC 7396 JSON Merge Patch stored as append-only versioned rows.

Storing a merge patch instead of a full tree means that when we update the base tree (for example, adding a new bare-metal pool), every org that did not override that particular entry automatically inherits the change.

Routing customer workloads is straightforward. Say we want to move one org onto a new bare-metal pool before everyone else: pointing its root default at the new pool is a one-key patch:

{
  "default": ["bare metal Chicago", "backup infra stack"]
}

Once we had sufficiently large infra pools in both the US and Europe, adding data residency was a quick change on top of the routing tree. For any org that wants its workloads restricted to a particular region, we switch its base tree to US or EU, where every product resolves only to infra pools in that region. However, there is an additional cost for data residency, which comes from actually storing data in that region, requiring us to set up and maintain dedicated deployments for each region, including localized databases and other data stores.

Bring your own cloud

The same scheduler also powers BYOC (bring your own cloud), where customers run WarpBuild runners in their own AWS, GCP, or Azure accounts. A BYOC runner is tied to the customer's cloud account, and we are only the orchestrator, so the jobs skip the routing tree, and the backend launches the VM directly via the cloud provider APIs. Everything else, from picking up the job to cleaning up the VM, follows the same path as jobs on our own infra.

Conclusion

Overall, moving off KubeVirt, consolidating both fleets onto one Nomad control plane, and adding the routing tree gave us simpler operations.

Today, we run millions of jobs on a typical weekday with very high consistency despite the heterogeneous hardware underneath, because of the scheduling layer we have invested in. It handles cache locality, BYOC, data residency, and OS and infra stacks, so customers get the same seamless experience regardless of where their jobs land.

Reliability is extremely important, since a stuck job blocks a customer's work. Alongside the scheduler, we have put extensive monitoring, alerting, and automated checks in place, like the bad-host check above, to catch problems early.

On this page