Back to Calculator

How to Optimize CI/CD Costs

Most teams can cut their CI/CD bill by 40-70% without changing platforms. Here are the techniques that actually work.

Quick Wins (Under 1 Day Each)

Enable concurrency cancellation
15-30% fewer minutes
Add dependency caching
3-8 mins per build
Skip CI on docs commits
Varies by docs volume

Build Time Optimisation

Parallelise Test Suites

40-70% reduction in build duration

Split your test suite across multiple jobs running in parallel. Most CI platforms support matrix builds. A test suite that takes 20 minutes sequentially can often be completed in 5 minutes across 4 parallel jobs.

How to Implement

Use matrix strategy in GitHub Actions or parallel keyword in GitLab CI to split tests by file groups or test type. Aim for roughly equal runtime per shard.

Fail Fast Configuration

15-30% fewer billed minutes

Configure your pipeline to cancel in-progress builds when a new push is received on the same branch. Most developers push multiple times before a PR is ready. Running all intermediate builds wastes significant compute.

How to Implement

Enable concurrency groups in GitHub Actions with cancel-in-progress: true. Use GitLab CI's interruptible: true flag on jobs.

Selective Job Triggering

Up to 60% minutes saved

Not every commit needs to run every job. Changes to documentation should not trigger a full test suite. Changes to the frontend should not run backend integration tests.

How to Implement

Use path filters (GitHub Actions: paths), rules with changes (GitLab CI), or custom scripts to detect what changed and skip unaffected jobs.

💾

Caching Strategies

Dependency Cache

3-8 minutes saved per build

Downloading npm packages, pip dependencies, or Maven artifacts on every build is slow and wasteful. A well-configured dependency cache restores in seconds and invalidates only when lock files change.

How to Implement

Cache node_modules keyed on package-lock.json hash. Cache pip wheels keyed on requirements.txt hash. Most CI platforms have built-in cache actions for common ecosystems.

Docker Layer Caching

5-15 minutes saved per image build

Building Docker images from scratch on every pipeline run is one of the biggest CI cost drivers. Docker layer caching re-uses unchanged layers, often reducing image build time from 10 minutes to under 60 seconds.

How to Implement

Use GitHub Actions cache-from and cache-to options with gha mode. GitLab CI supports Docker BuildKit layer caching via DOCKER_BUILDKIT=1.

Build Output Cache

50-80% reduction for incremental builds

Compilation outputs (TypeScript, Rust, C++ object files) can be cached and reused when source files have not changed. Tools like Nx, Turborepo, and Bazel support remote caching that persists across machines.

How to Implement

Evaluate Nx Remote Cache or Turborepo Remote Cache for JS monorepos. For compiled languages, tools like ccache (C/C++) or sccache (Rust) provide layer-agnostic caching.

🖥️

Self-Hosted Runners

Break-Even Analysis

50-70% savings above 50k mins/month

Self-hosted runners eliminate per-minute charges but introduce infrastructure and maintenance costs. The break-even point versus GitHub Actions Linux runners is typically 40,000-60,000 build minutes per month.

How to Implement

Calculate: (monthly build minutes x $0.008) vs (VM cost + maintenance). A c5.2xlarge spot instance on AWS runs 24/7 for ~$70/month and handles 30+ jobs per hour.

Ephemeral Runners

Lower waste, better security

Persistent self-hosted runners accumulate state, leading to flaky builds and security risks. Ephemeral runners start fresh for each job and terminate when done, matching the reliability of hosted runners.

How to Implement

Use actions-runner-controller (ARC) on Kubernetes for GitHub Actions. GitLab supports ephemeral runner autoscaling via Docker Machine or Kubernetes executor.

Spot/Preemptible Instances

60-80% infrastructure cost reduction

CI builds are excellent candidates for spot instances because they are short-lived and can be retried on failure. Running your runner fleet on AWS Spot or GCP Preemptible VMs can cut infrastructure costs by 60-80%.

How to Implement

Configure runner managers with mixed fleet (some on-demand for reliability, majority spot). Use spot instance diversification across multiple instance types to improve availability.

See how these optimisations affect your platform costs.

Open the Calculator