Developers complain that the CI pipeline takes 40 minutes. How would you speed it up?
IntermediateScenarioReal-world scenarios
Answer
In one line: Measure where the 40 minutes go, then remove waste: caching, parallel jobs, running only what's needed, faster tests and better runners — aiming for fast feedback on PRs (under about 10 minutes).
Step 1 — Measure
- Break down the duration by stage over the last 20–50 runs.
- Look for waiting time too (jobs queued for a free runner).
Step 2 — Quick wins
- Dependency caching — Maven/Gradle, npm, pip, Go module caches.
- Docker layer caching — reorder the Dockerfile so dependency installs are cached; use BuildKit with a registry cache.
- Parallelise — run lint, unit tests, SAST and dependency scans at the same time instead of one after another.
- More/bigger runners — if jobs wait in a queue, add autoscaling runners.
Step 3 — Structural improvements
- Split tests across several runners (test sharding).
- Test only what changed — path filters, or Nx/Turborepo/Bazel to build only affected projects in a monorepo.
- Move slow suites — full E2E, performance and long security scans run after merge or nightly, while PRs run a fast, focused set.
- Fail fast — compile and lint first, so broken code fails in 1–2 minutes.
- Fix flaky tests — automatic retries waste time and hide problems.
- Build once — reuse the built artifact in later stages instead of rebuilding.
- Remove unnecessary steps — duplicate scans, unused stages, verbose uploads of huge artifacts.
Step 4 — Keep it fast
- Track pipeline duration as a metric and alert if it creeps up.
- Treat pipeline speed as a team goal.
Example result:
| Change | Saved |
|---|---|
| Maven cache | 7 min |
| Docker layer cache | 6 min |
| Parallel test & scan jobs | 10 min |
| Test sharding (4 runners) | 8 min |
| E2E moved to post-merge | 4 min |
| Total: 40 → ~5 min |
Tip for interviews: numbers make this answer memorable — share real before/after figures if you have them.
More on Real-world scenarios
The website is slow. How do you troubleshoot it?IntermediateA deployment to production just failed halfway. What do you do?IntermediateSomeone accidentally committed an AWS access key to a public GitHub repository. What do you do?IntermediateYour production disk is 95% full and the alert just fired. What do you do?IntermediateHow would you set up CI/CD for a brand-new microservice from scratch?IntermediateYour cloud bill doubled this month. How do you find out why and reduce it?Intermediate