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:
- 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 } - 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). - Run jobs in parallel — lint, unit tests and security scans don't need to wait for each other.
- Split tests — divide a big test suite across several runners (test sharding).
- Run only what changed — path filters in monorepos; tools like Nx, Turborepo or Bazel build only affected projects.
- Fail fast — put quick checks (lint, compile) first so broken code fails in one minute, not twenty.
- Move slow tests — run the full end-to-end and performance suites after merge or nightly, keep a smaller smoke set in PRs.
- Faster runners — bigger machines, or self-hosted runners close to your registries and artifact stores.
- Fix flaky tests — reruns waste time and destroy trust.
- 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.
More on CI/CD practices
What is "pipeline as code", and why is it better than configuring pipelines in a UI?BeginnerWhat is a build agent or runner?BeginnerWhat are pipeline triggers?BeginnerWhat is a quality gate in a CI/CD pipeline?BeginnerWhat are secrets in CI/CD, and how should they be handled?BeginnerWhat is a monorepo vs a polyrepo, and how does it affect CI/CD?Beginner