| name | design-ci-pipeline |
| description | Use when designing or improving a continuous integration pipeline for a software project |
Design CI Pipeline
Design a CI pipeline that gives fast, reliable feedback on every commit and enables trunk-based development at scale.
Why This Is Best Practice
Adopted by: Google, Netflix, Amazon, Etsy — all DORA elite performers with documented CI/CD practices
Impact: DORA research (Accelerate, 2018) shows elite performers have 46× more frequent deployments and 2,555× faster lead time to change; fast CI (<10 min) is a key differentiator between elite and low performers.
Why best: A well-designed CI pipeline is the heartbeat of software delivery. It enforces quality gates, provides rapid feedback, and is the foundation that makes trunk-based development safe at scale. Slow or flaky CI is one of the highest-leverage engineering problems to fix.
Steps
- Define pipeline stages — Minimum viable: checkout → install → lint → test → build → security scan. Add: integration tests, performance tests, deploy-to-staging for pre-merge validation.
- Target <10 minutes to green — Parallelize test stages; use test sharding; cache dependencies aggressively. DORA data: pipelines >10 min cut developer flow significantly.
- Fail fast — Run the fastest checks first (lint, unit tests); run slower checks (integration, E2E) in parallel or after fast checks pass.
- Make the pipeline the gate — No merge to main without green CI. Enforce via branch protection; never allow bypassing.
- Eliminate flakiness — Track flaky tests (retry logic with reporting); quarantine and fix flaky tests within one sprint. Flaky CI erodes trust and causes developers to ignore failures.
- Cache and artifact management — Cache: npm/pip/Maven deps, Docker build layers. Share build artifacts between stages; do not rebuild the same binary twice.
- Instrument the pipeline — Measure: mean time to feedback, flaky test rate, pipeline duration trend. Alert when median duration exceeds SLO.
Rules
- Every commit to main must trigger the full pipeline.
- Secrets must never be echoed in pipeline logs; mask all secrets.
- Pipelines must be defined as code (YAML) in the repository — no click-ops configuration.
- Differentiate PR pipelines (fast feedback) from post-merge pipelines (full validation + deploy).
Examples
GitHub Actions structure:
jobs:
lint:
unit-test:
build:
security:
integration:
Total wall time: ~8 minutes via parallelism.
Common Mistakes
- Sequential stages — lint → test → build → scan run one-at-a-time; doubles pipeline time versus parallel.
- No dependency caching —
npm install from scratch on every run adds 2-3 minutes; cache the node_modules layer.
- Treating flaky tests as acceptable — a 5% flaky rate means 1 in 20 PRs gets a false failure; developers start ignoring CI.