Why this matters
Continuous integration catches mistakes minutes after they're made. Continuous delivery makes releasing boring, which is the goal. Teams that deploy many times a day aren't braver; they have better automation.
Core ideas
- CI (continuous integration): every push runs the checks: format, lint, type-check, unit tests, build, security scans.
- CD (continuous delivery/deployment): every green build is deployable (delivery), or is deployed automatically (deployment).
- Environments: dev → staging (production-like) → production. Promote the same build artefact; don't rebuild per environment.
- Quality gate: a check that blocks merging when it fails. Never lower a gate silently to get a build through.
A typical pipeline
# .github/workflows/ci.yml (shape, not a full file)
on: [push, pull_request]
jobs:
lint: { steps: [checkout, setup, "ruff check .", "ruff format --check ."] }
types: { steps: [checkout, setup, "mypy --strict src"] }
test: { steps: [checkout, setup, "pytest -q --maxfail=1"], services: [postgres] }
build: { needs: [lint, types, test], steps: ["docker build -t app:${{ github.sha }} ."] }
deploy-staging: { needs: build, if: "github.ref == 'refs/heads/main'" }
Run independent jobs in parallel; keep the whole pipeline under ~10 minutes so people don't stop waiting for it.
Release strategies
| Strategy | How | Use when |
|---|---|---|
| Rolling | Replace instances a few at a time | Default for stateless services |
| Blue-green | Run new version alongside old; switch traffic at once; switch back to roll back | Need instant rollback |
| Canary | Send a small % of traffic to the new version, watch metrics, expand | Risky changes, including model or prompt changes |
| Feature flag | Code ships dark; turned on per user or % | Decouple deploy from release; A/B tests |
| Shadow | New version gets copies of real traffic; its output is logged, not used | New models or scoring logic (P7's shadow model) |
Database migrations without downtime: expand → migrate → contract
- Expand: add the new column/table, nullable or with a default. Old code still works.
- Migrate: deploy code that writes both; backfill old rows in batches.
- Switch reads to the new structure.
- Contract: after everything uses the new shape, drop the old column.
Never rename or drop a column in the same deploy as the code that stops using it.
Releasing AI changes
A prompt or model change is a behaviour change with no compiler to catch mistakes. Treat it like code: versioned, reviewed, gated by evals in CI, released by canary or shadow, with instant rollback by repointing a version label (Q15, Q20).
Common mistakes
- Building different artefacts for staging and production.
- Flaky tests that everyone re-runs until green; fix or quarantine them.
- Migrations that lock large tables during business hours.
- Shipping a new prompt straight to 100% of traffic.
Interview follow-ups
- "CI takes 40 minutes. How do you speed it up?" Parallelise jobs, cache dependencies, run only affected tests on PRs (full suite on main), split slow E2E suites, fix the slowest tests first.
- "How do you roll back a bad migration?" Avoid needing to: use expand/contract so the old code still works; roll back the code, not the schema; write forward fixes for data.
- "How do you release a new model safely?" Evals in CI, shadow traffic, canary by percentage with quality and cost dashboards, instant rollback by config.
Check yourself
What's the difference between a canary and a feature flag?
A canary routes a slice of traffic to a new deployment; a feature flag turns behaviour on or off inside one deployment, often per user. They're often combined.
How do you rename a column used by a live service?
Expand (add the new column), dual-write and backfill, switch reads, then contract (drop the old column) in a later release.
Build it
Add a GitHub Actions workflow to a project with parallel lint, type and test jobs, and a build job that depends on all three.