This article was prepared with AI assistance. Originally published on the Celesto blog.

A 2% EC2 Spot interruption rate sounds harmless in a spreadsheet. On a 10-job GitHub Actions matrix with independent interruptions and no retries, a 2% per-job reclaim rate interrupts 18.3% of first attempts (1 - 0.98^10). Bump the reclaim rate to 5% in the model, and 40.1% of first attempts have at least one interruption.

Teams put CI runners on EC2 Spot instances because Spot compute looks 60% to 75% cheaper than On-Demand. The hidden catch is that CI jobs cannot checkpoint and move when AWS takes the VM back. Every reclaim looks like a flaky test in GitHub, forces a full rerun from minute zero, and burns both compute and engineer focus.

The table shows the probability of at least one interruption on the first attempt, assuming equal, independent per-job risks.

Jobs in your PR workflow 1% Spot reclaim rate 2% Spot reclaim rate 5% Spot reclaim rate
1 job 1.0% interrupted 2.0% interrupted 5.0% interrupted
5 parallel jobs 4.9% interrupted 9.6% interrupted 22.6% interrupted
10 parallel jobs 9.6% interrupted 18.3% interrupted 40.1% interrupted
20 parallel jobs 18.2% interrupted 33.2% interrupted 64.2% interrupted

If your CI pipeline has more than a handful of jobs per pull request, Spot interruptions are not a rare edge case. They become a daily tax on your merge queue.

What happens during an EC2 Spot interruption

AWS sells spare EC2 capacity at steep discounts with one clear rule: when On-Demand customers need those servers back, AWS reclaims them.

EC2 emits a Spot Instance interruption notice two minutes before termination, on a best-effort basis. You can read that notice from the instance metadata service (IMDS) or from an EventBridge rule.

Two minutes works well for a stateless web server behind a load balancer. You stop new requests, finish active HTTP calls in a few seconds, and exit cleanly.

A GitHub Actions job does not work that way.

Timeline of a 12-minute CI job interrupted by an EC2 Spot reclaim at minute 11, which triggers a full 12-minute rerun for 23 billed minutes total.

A running pytest, cargo test, or Playwright suite holds state across memory, local disk, PostgreSQL containers, and Docker build layers. You cannot serialize that state in 120 seconds and resume it on a second EC2 instance.

When minute 11 arrives, EC2 kills the VM. The actions/runner process vanishes without a graceful exit, GitHub times out the runner heartbeat, and the workflow check turns red with a generic message like The self-hosted runner lost communication with the server.

Why matrix math turns a 2% Spot rate into 18% broken PRs

Most modern repositories do not run one monolithic job. A typical pull request fans out into a matrix: lint, typecheck, unit tests across two runtimes, integration tests, Docker build, and end-to-end browser checks.

If a PR requires all n jobs to pass and each job faces an independent Spot reclaim probability p, the chance that at least one job dies mid-run is:

P(PR fails due to Spot) = 1 - (1 - p)^n 

Three factors affect how this model maps to a real workflow:

  • Longer jobs have higher exposure. A 25-minute end-to-end suite sits on a Spot VM 5x longer than a 5-minute unit test, so it faces a much higher chance of a reclaim before it finishes.
  • Jobs can share the same instance pool. Their interruptions may be correlated, so compare observed interrupted workflows with the independent-job estimate.
  • Merge queues multiply the blast radius. If a merge queue batches 4 PRs together and one Spot runner dies at minute 14, the entire batch resets and blocks every developer behind it.

The rerun bill and the developer-time tax

The direct compute waste is easy to measure. If a 12-minute integration job dies at minute 11 and reruns cleanly for 12 minutes, AWS bills you for 23 minutes of compute, EBS gp3 storage, and network traffic for a 12-minute job.

If a developer clicks Re-run all jobs instead of Re-run failed jobs, you pay for the entire 10-job matrix twice.

The bigger cost never shows up on your AWS invoice. It shows up in engineer attention:

  1. Phantom flake triage. Most developers do not check AWS EventBridge when a PR turns red. They open the test log, see a truncated trace, and spend 15 to 20 minutes to verify whether their commit broke an unrelated test.
  2. Broken flow state. An extra 12 to 20 minutes of retry wait time pushes a developer onto another branch or another task. Context switches cost far more than $0.02 of EC2 Spot compute.
  3. Eroded trust in CI. Once engineers learn that "red CI usually just needs a retry," they stop trust-checks on real failures and reflexively hit Re-run on genuine bugs.

Four ways teams mitigate Spot reclaims (and what each fix costs)

If your CI jobs must stay inside your own AWS account, you can cut Spot pain sharply with four concrete practices. Every one of them adds engineer maintenance or eats into your Spot savings:

  1. Use price-capacity-optimized across wide instance pools. Configure your EC2 Fleet or autoscaler with the price-capacity-optimized allocation strategy across multiple instance families (such as m7a, m8a, c7i, c8i) and multiple Availability Zones. Narrow single-family pools get reclaimed far more often.
  2. Keep every CI job under 10 minutes. Split 30-minute test suites into sharded 5-minute jobs. Shorter jobs have lower reclaim exposure and cost less to retry.
  3. Automate disconnect retries. Wire a webhook or controller to detect lost communication with the server failures and automatically re-trigger only the interrupted job. That keeps developers out of the loop, though you still pay for the dead minutes and extra wait time.
  4. Route release, deploy, and long jobs to On-Demand. Never put a 25-minute production build or database migration on Spot. Keep Spot for short, idempotent PR checks, and accept On-Demand prices (3x to 4x higher than Spot) for critical paths.

Notice what happens as you layer those fixes together: you spend engineer hours on fleet allocation, fallback logic, and retry automation, and you still pay AWS for NAT Gateways, internet egress, public IPv4 addresses, EBS volumes, and CloudWatch logs. We calculated the full AWS invoice in Why Self-Hosted GitHub Actions Runners on AWS Cost More Than the EC2 Bill.

When to use On-Demand capacity for CI

Track interrupted jobs, rerun duration, and time to a passing check by workflow. Move jobs with high retry costs or release dependencies to On-Demand capacity first. Compare the resulting bill and wait time with the same workloads on Spot.

Frequently asked questions

How much notice does AWS give before it terminates a Spot instance?

AWS emits a best-effort Spot Instance interruption notice two minutes before termination. You can poll the instance metadata endpoint or subscribe via Amazon EventBridge, but two minutes is rarely enough to finish or checkpoint an active CI build.

Can GitHub Actions automatically retry a job killed by a Spot interruption?

Not natively out of the box. GitHub marks the job failed or cancelled when the runner disconnects. You need either manual reruns, a workflow-level retry wrapper, or an external webhook/orchestrator that calls the GitHub API to rerun failed jobs.

Which EC2 Spot allocation strategy has the fewest interruptions for CI?

AWS recommends price-capacity-optimized across a broad list of equivalent instance families and multiple Availability Zones. It chooses pools with both low prices and deep spare capacity, which lowers interruption frequency compared to lowest-price.

Should I run deploy or release jobs on EC2 Spot instances?

No. A mid-deploy interruption can leave Terraform locks, partial container pushes, or half-finished database migrations behind. Keep stateful or release-critical workflows on On-Demand instances or a managed runner that does not reclaim VMs mid-job.