Skip to content

CI/CD and release safety

Phase 5 · Shipping and operating · 15 min read · 3 Atlas cases linked

What you'll be able to do

  • Explain what CI, continuous delivery, and continuous deployment each guarantee.
  • Design a pipeline that checks each integrated revision and promotes the same tested artifact through environments.
  • Choose a gradual release and a safe recovery path from observed failures.

Integrate small changes continuously

You can test a branch perfectly and still break main when you merge it: another branch may have changed the same assumption. Continuous integration (CI) means merging small changes into a shared branch often and verifying each change automatically. A pull request normally runs checks before merging; a push to main runs them again on the combined code. CI gives fast evidence about that exact revision, not a guarantee that production will work.

Small batches make failures easier to locate. If you merge ten changes before testing, a failure has ten plausible causes. Test after each merge and you usually investigate one. Integration pain grows with branch size and age as code diverges. Keep branches short lived, and split large work into changes that can safely land separately.

The three terms describe different points on the path to users:

Practice What happens after a change
CI Changes are integrated often and automatically checked.
Continuous delivery A passing revision is packaged and kept ready for a deliberate production release.
Continuous deployment Every passing revision is released automatically, subject to the pipeline's gates.

Delivery does not require an automatic production release. Deployment does. Both need a trustworthy CI foundation.

Build a pipeline that gives useful evidence

A pipeline starts on an event such as a push or pull request. Each job runs checks or produces an output. A simple dependency graph might look like this:

A CI pipeline is a dependency graph: checks run in parallel, any failure stops the line.

Linting catches style and simple errors; a type checker finds inconsistent type use; unit tests check small behaviors. The build creates a versioned image or package. Integration tests exercise components together, including a disposable database when needed. A security scan inspects dependencies and the artifact. Publishing makes the passing artifact available to deploy. A failed required gate stops promotion. Pull requests normally stop after the checks; publish and deploy run only for revisions on the shared branch.

Store the pipeline definition with the code, often as YAML. This is pipeline as code: changes to the release process can be reviewed like application changes. The following is a generic sketch, not syntax for a particular CI service:

on: [push, pull_request]
jobs:
  test:
    run: python -m pytest tests -q
  build:
    needs: [test]
    run: build-image
  publish:
    needs: [build]
    run: publish-image

Run independent jobs in parallel. Fail fast: do not build or deploy a revision whose required tests failed. Cache downloaded dependencies between runs, keyed by the dependency lockfile so stale inputs are not reused. An artifact is a build output; keep its version or digest so later stages use those exact bytes. A cache is an optimization, never evidence that a build passed.

Flaky tests are CI poison. If a test sometimes fails on identical code, people rerun or ignore red builds, and the gate stops signaling real problems. Fix the nondeterminism or isolate the test while you investigate; do not declare a failing run green by habit.

Keep the shared branch releasable

Trunk-based development keeps work close to main. Merge small reviewed changes frequently, and keep unfinished behavior behind a feature flag. Required checks and code review act as quality gates. Branch protection can prevent a merge until both pass, and can require the branch to be current with main. The aim is to keep main green: every revision should be a credible release candidate.

Review and automation answer different questions. Tests check known behavior; reviewers can question the goal, failure handling, and privacy. Keep changes small enough to inspect and reverse. If main becomes red, fix or revert the cause before stacking more changes on it.

Build once, then promote

Use development for fast feedback, staging to rehearse production-like behavior, and production for real traffic. Build one immutable artifact from a commit, test it, then promote that same artifact through the environments. Rebuilding separately can pull different dependencies or base images; then staging tested different bytes from production. For example, if image digest sha256:abc... passes staging, the deploy step should identify that digest in production too.

Put environment settings outside the artifact: database addresses, feature settings, and credentials differ by environment. Supply them at deploy or runtime, with access limited to the jobs that need them. The configuration and secrets lesson covers this in detail. Tests should use disposable credentials and services, not production secrets.

Database changes need care because old and new application versions may run at once. Use expand/contract: first add a compatible column or table; deploy code that works during the transition; backfill if needed; only later remove the old shape. A destructive migration can make application rollback impossible. Rehearse migrations in staging and plan recovery.

Release gradually and recover deliberately

Rolling deployment replaces instances a few at a time. It uses existing capacity, but old and new versions coexist, so interfaces and schemas must be compatible. Blue-green keeps two complete environments: serve traffic from blue, deploy and check green, then switch traffic. Switching back can be quick if blue and its data remain compatible. The extra environment costs capacity.

Canary sends a small fraction of traffic to the new version, compares health signals, and increases the fraction only if it stays healthy. Suppose the baseline has 20 errors in 2,000 requests (1%) and the canary has 9 in 300 (3%). The canary error rate is 3 times the baseline; a gate allowing at most 1.5 times should roll it back. Require enough representative traffic before promotion; also set immediate stop conditions for severe errors or health-check failures. Watch latency and business outcomes as well as errors. Automated analysis can pause or roll back a bad canary, but its thresholds need review: tiny samples and changing traffic mix can mislead.

baseline_rate = 20 / 2000
canary_rate = 9 / 300
print(canary_rate / baseline_rate)  # 3.0

A feature flag separates deployment from release. You can deploy dormant code, then enable it for staff or a stable percentage of users. Flagged paths still need tests, and old flags need removal. If a release fails, rollback routes traffic to a known good artifact when the old code can still use the data. Roll forward deploys a fix when data or schema changes make rollback unsafe. Keep immutable artifacts and backward-compatible schemas so rollback is an actual option, then practise the switch.

Measure the flow, not just the build

DORA, a long-running research program on software delivery, originally popularized four metrics, still often called the DORA four; its current model uses five:

Signal Meaning
Deployment frequency How often changes reach production.
Lead time for changes Time from committing a change to its production release.
Change failure rate Fraction of deployments that cause a failure requiring intervention.
Failed deployment recovery time Time to recover from a deployment that caused a failure requiring intervention.
Deployment rework rate Fraction of deployments that are unplanned work responding to a production incident.

Read them together. Faster deployments are not progress if failures and recovery time climb. Use these measures to find friction and risk in the process, not as targets that reward gaming a metric. A slow pipeline may indicate oversized tests or repeated setup; a high failure rate may point to missing gates or unsafe rollouts.

For AI engineers

For AI engineers

Your training script may run successfully on one notebook dataset while failing when a column disappears tomorrow. Put data-schema checks, a small training smoke test, and evaluation gates in CI. Keep expensive full training in a separate, traceable pipeline; continuous training should publish a candidate model, not silently replace the live one.

Version the code, data snapshot, and model artifact together. A model registry can identify which weights passed which evaluation and which version is serving. For a new model, shadow production requests to it without using its answers, compare outputs and operational metrics, then canary a small share of real responses. Record the exact model, code, and data versions so a rollback restores a known combination. The MLOps cases under See it in the wild, below this lesson, show how release pipelines apply to ML systems.

Common mistakes

  • Rebuilding for each environment: staging cannot validate production if the builds differ. Promote one immutable artifact.
  • Slow or flaky checks: a gate people routinely ignore is ineffective. Keep fast feedback early and repair flaky tests.
  • Production secrets in tests: use isolated test services and narrowly scoped credentials.
  • Unrecorded manual release steps: put repeatable checks and promotion in the pipeline so a tired operator is not the only safety mechanism.
  • Skipping staging for a small change: small code edits can still change migrations, configuration, or dependencies.
  • One-way migrations without a recovery plan: separate compatible schema expansion from later cleanup, and decide whether to roll back or forward.

Check yourself

A pull request passes tests, but the merged revision fails on main. What does CI tell you to do next?

Investigate the combined revision and fix or revert it promptly. Checks on the branch did not prove the merged code would pass; keep main green before adding more changes.

Staging builds an image from the same commit as production, but production rebuilds it later. Is this promotion of the tested artifact?

No. The second build may produce different bytes. Publish a versioned artifact once and deploy that exact digest to both environments.

A canary has 2 errors in 10 requests while baseline is at 1%. Should a gate immediately roll back?

Do not promote on ten requests. Pause or roll back if the failures breach an urgent stop condition, such as severe errors or failed health checks; otherwise collect more representative data. Ten requests are too few to treat the observed 20% as a reliable estimate.

Your new code removed a database column in the same release. Why might switching to the old image fail?

The old code may still require that column. Expand/contract migrations keep both code versions compatible during the rollout and rollback window.

Lab

Build a small, deterministic release simulator in code/ci-cd/. Plan parallel job stages, then execute jobs with fail-fast behavior. Use request and error counts to decide whether a canary waits, promotes, or rolls back (sample-size and error-ratio gate only; no urgent stop conditions). Switch and restore blue-green versions; add stable percentage feature flags. The README defines the edge cases; make the starter pass its tests. Run: cd code/ci-cd && PYTHONPATH=starter python -m pytest tests -q

Go deeper

See it in the wild

Open these real architectures and find the idea in the diagram. Predict how it is used before you read the analysis.