CI/CD
CI/CD is the machinery that turns a commit into a running, verified artefact without a human copying files over SSH. Interviews ask about it because it exposes how you think about risk: what you verify, what you can undo, and how you keep a database compatible with two versions of your code at once.
The 60-second answer
Section titled “The 60-second answer”Continuous integration means every commit is merged into trunk and verified by an automated build and test run. Continuous delivery means every green build produces a deployable artefact; continuous deployment means it goes to production automatically. A pipeline is stages — lint, test, build, scan, staging, production — each gating the next, with the artefact built once and promoted rather than rebuilt. You deploy with blue-green or canary to limit blast radius, roll back by redeploying the previous immutable artefact, and make database changes backward-compatible so code and schema can be rolled independently.
The pipeline, stage by stage
Section titled “The pipeline, stage by stage”| Stage | Purpose | Typical failure |
|---|---|---|
| Unit tests | Fast feedback | Flaky tests eroding trust |
| Build | Produce an immutable artefact | Rebuilding per environment |
| Integration tests | Real database, real queue | Shared, dirty environments |
| Security scan | Dependencies, image, secrets | Blocking on unfixable findings |
| Deploy staging | Smoke test the real thing | Staging diverging from prod |
| Deploy production | Release | No rollback path |
Build once, promote everywhere: the artefact tested in staging must be byte-identical in production. Fail fast, too — cheapest checks first, so breakage is caught in minutes.
on: { pull_request: {}, push: { branches: [main] } }jobs: test: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 with: { node-version: 22, cache: npm } - run: npm ci && npm test build: needs: test if: github.ref == 'refs/heads/main' runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - run: docker build -t registry.example.com/api:${{ github.sha }} .Trunk-based development
Section titled “Trunk-based development”Short-lived branches merged into main at least daily, with feature flags hiding unfinished work.
Long-lived branches produce merge conflicts proportional to their age and encourage big-bang
integration. It survives on small pull requests with fast review, flags hiding unfinished work, and
a fast, reliable test suite — if main breaks, everyone is blocked.
Build caching
Section titled “Build caching”Caching is the difference between a two-minute and a twenty-minute pipeline: dependency caches keyed
on the lockfile hash, layer caches in container builds (--cache-from), test caches and parallel
sharding. The cache key is the whole game — key on the branch name and you get almost no reuse.
Blue-green deploys
Section titled “Blue-green deploys”Two identical environments: deploy to the idle one, verify, then switch the router or DNS. Rollback is switching back.
- Pros: instant rollback; the new version is verified before traffic.
- Cons: double the infrastructure, and the shared database must be compatible with both versions.
Canary deploys
Section titled “Canary deploys”Send a small share of traffic to the new version, watch error rate and latency, then ramp up.
- Pros: real traffic on the new version; blast radius limited to the canary share.
- Cons: needs good metrics and automated analysis, and two versions run concurrently — so the schema-compatibility rule applies.
| Strategy | Blast radius | Rollback | Cost |
|---|---|---|---|
| Recreate | Everything, briefly down | Slow | Lowest |
| Rolling | A fraction at a time | Medium | Low |
| Blue-green | None until switch | Instant | Double |
| Canary | A small slice | Fast | Low–medium |
Rollbacks
Section titled “Rollbacks”A rollback is part of the deploy, not plan B. You need immutable artefacts so the previous version
still exists; a one-command rollback (kubectl rollout undo, redeploy the previous tag, flip the
load balancer); and a decision rule such as “error rate above X for Y minutes, roll back”, because
humans under pressure argue and thresholds do not.
Database migrations
Section titled “Database migrations”This is where most “zero-downtime” claims collapse. The rule: every schema change must be backward compatible with the currently deployed code, because during a deploy both versions run.
The expand/contract pattern, in three deploys:
- Expand — add the new nullable column or table. Old code ignores it; new code can dual-write.
- Migrate — backfill in batches, outside the request path.
- Contract — switch reads, then in a later deploy drop the old column.
ALTER TABLE users ADD COLUMN email_normalised text;CREATE INDEX CONCURRENTLY ON users (email_normalised);Never in one step while serving traffic: renaming a column, dropping a column the old version still
reads, adding NOT NULL without a default, or a long ALTER TABLE holding a lock. Note that
CREATE INDEX CONCURRENTLY cannot run inside a transaction, which many tools assume by default.
Follow-up questions
Section titled “Follow-up questions”- How do you roll back a deploy that included a migration?
- Why build the artefact once instead of per environment?
- What does a canary need in order to be safe?
- How do you keep
mainreleasable with ten engineers merging daily?
Common traps
Section titled “Common traps”- Rebuilding the image per environment. Different artefact, different bugs.
- Migrations and code deploy in the same instant. One of them will be incompatible.
- Manual approval as the only safety net. It is a gate, not a rollback strategy.
latesttags. No traceability, no reliable rollback.- Staging that differs from production. Confidence theatre.