How to Run CI on Spot Instances to Cut Cost and Waste
Spot instances sell spare datacenter capacity that would otherwise sit idle, at a large discount.
Spot and preemptible instances use hardware the cloud provider already runs and would otherwise waste. For interruptible CI work they cut cost sharply; the price is that the provider can reclaim the machine, so jobs must tolerate a mid-run stop.
Steps
- Provision the runner pool on spot or preemptible instances.
- Keep jobs short and idempotent so a reclaimed machine can be retried cleanly.
- Retry the queued job automatically when an instance is interrupted.
Retry interrupted work
.github/workflows/ci.yml
jobs:
build:
runs-on: [self-hosted, spot]
steps:
- uses: actions/checkout@v4
- uses: nick-fields/retry@v3
with:
max_attempts: 2
timeout_minutes: 20
command: npm ci && npm run buildTradeoffs
- Never put non-interruptible deploys on spot; reserve on-demand capacity for those.
- Interruptions cost a re-run, so spot pays off only when the discount beats the retry rate.
Related guides
How to Scale Self-Hosted CI Runners to Zero When IdleConfigure ephemeral self-hosted GitHub Actions runners that scale to zero when no jobs are queued, so idle ma…
How to Balance CI Cost, Carbon, and SpeedUnderstand the honest tradeoffs between CI cost, carbon, and feedback speed, and choose per-workflow defaults…