How do you make a slow CI/CD pipeline faster?

BeginnerConceptCI/CD practices
Answer

In one line: Find where the time goes, then cache dependencies, run jobs in parallel, avoid repeating work, and only run what's needed for each change.

Step 1 — Measure: look at the duration of each stage over the last few runs. Optimise the slowest parts first.

Common techniques:

  1. Cache dependencies — keep ~/.m2, node_modules (or the npm cache), pip caches and Go modules between runs.
    - uses: actions/setup-node@v4
      with: { node-version: 20, cache: npm }
    
  2. Docker layer caching — order the Dockerfile so rarely-changing layers (dependency install) come before frequently changing ones (copying source code), and use BuildKit cache (--cache-from, registry cache).
  3. Run jobs in parallel — lint, unit tests and security scans don't need to wait for each other.
  4. Split tests — divide a big test suite across several runners (test sharding).
  5. Run only what changed — path filters in monorepos; tools like Nx, Turborepo or Bazel build only affected projects.
  6. Fail fast — put quick checks (lint, compile) first so broken code fails in one minute, not twenty.
  7. Move slow tests — run the full end-to-end and performance suites after merge or nightly, keep a smaller smoke set in PRs.
  8. Faster runners — bigger machines, or self-hosted runners close to your registries and artifact stores.
  9. Fix flaky tests — reruns waste time and destroy trust.
  10. Build once — reuse the same artifact in later stages instead of rebuilding.

Example: a Java pipeline took 28 minutes. The team cached Maven dependencies (−6 min), reordered the Dockerfile for layer caching (−5 min), ran tests and scans in parallel (−7 min) and moved end-to-end tests to post-merge (−4 min). It now takes about 6 minutes.

Tip for interviews: always start with "I measured where the time was going" — then give before/after numbers.

All DevOps Fundamentals questions

More on CI/CD practices