Rana Maninder Singh
Lesson 5 of 12DevOps & Platform Engineering

Lesson 5: Continuous Delivery and Deployment Strategies

Lesson opener

In one line: Continuous Delivery automates the path from merged code to a production-ready artifact; deployment strategies control how and when that artifact reaches real users.

Why it matters: At Northline, a botched Saturday-night deploy once rolled back three weeks of work and cost four hours of downtime — the root cause was a manual, all-at-once cutover with no staged validation. The patterns in this lesson exist precisely to prevent that.

Before this lesson: You should be comfortable with CI pipelines (#devops1–4), version-controlled branching (#git\*), and environment concepts (#cloud1). Familiarity with API contracts (#api5) helps when thinking about backward-compatible migrations.

Learning objectives

By the end of this lesson you will be able to:

  1. Distinguish Continuous Delivery from Continuous Deployment and choose the right model for a given team context.
  2. Design a multi-environment promotion pipeline with explicit go/no-go gates.
  3. Explain and implement blue-green, canary, and rolling deployment strategies, including their rollback paths.
  4. Use feature flags to decouple code deployment from feature release.
  5. Plan a database migration that does not break the running application during a zero-downtime deploy.
  6. Write a go/no-go checklist that captures automated and human approval criteria.

Lesson deliverable: A written deployment strategy document for a fictional Northline "Billing v2" service, covering environment chain, promotion gates, chosen deployment strategy, feature-flag plan, migration approach, and rollback procedure.

Prerequisites

ConceptWhere covered
CI pipelines and artifact publishing#devops1–4
Git branching and pull requests#git\*
Environment variables and secrets#cyber5, #setup8
REST API versioning#api5
Cloud environments overview#cloud1

Plain English: what is this really about?

Imagine you baked a cake. A CI pipeline is the kitchen — it checks that the cake rises, isn't burnt, and meets the recipe spec. Continuous Delivery is having that cake packaged, labelled, and sitting in the fridge, ready to serve at any moment. Continuous Deployment is the fridge automatically opening and sliding the slice onto the customer's plate the moment it is ready, no human hands required.

Most organisations sit somewhere between the two. Northline uses Continuous Delivery with mandatory human approval for production — the pipeline does all the work, but a release manager clicks "promote" after reviewing a dashboard.

The second half of the lesson is about how the cake reaches the plate without knocking over other plates already on the table. That is a deployment strategy. The three main ones are:

Feature flags let you deploy the new cake without actually serving it. The cake is in the fridge, but the flag is "off" — no customer sees it yet.


Walkthrough: Northline's Billing v2 release

Business objective

Northline's billing team is shipping a VAT calculation engine rewrite. The new code changes database schema and must coexist with the old code during the transition window.

Owners

RoleResponsibility
Platform engineerPipeline, environment config
Backend engineerMigration scripts, feature-flag integration
QA leadAcceptance criteria, go/no-go sign-off
Release managerProduction approval click
On-call SREMonitors error rates post-deploy

Repository and artifacts

The service lives in billing-service on the Northline mono-repo. The CI pipeline (see #devops2) produces a versioned Docker image (see #devops6) tagged billing:2.3.0-rc1 and pushed to the internal registry. Migration SQL files are versioned alongside the application code and never stored separately.

Environment chain

dev  →  staging  →  uat  →  production

Each environment is defined in its own Terraform workspace (#devops8) and separated by namespace in the secrets manager (#cyber5, #cloud8). A commit to main automatically promotes to dev. Promotion beyond that requires a passing gate.

Pipeline promotion gates

GateAutomated checksHuman approval
dev → stagingUnit + integration tests pass, image built, SAST scan cleanNone
staging → uatContract tests pass, migration dry-run succeeds, no critical CVEsNone
uat → productionSmoke tests pass, error rate < 0.1 %, latency P99 < 400 msRelease manager

Gates are enforced by the CI platform; a failed automated check blocks the pipeline hard. A human approval is a named sign-off stored in the pipeline audit log — not a Slack message.

Chosen strategy: canary with feature flag

Because Billing v2 touches financial calculations, the team chooses canary: 5 % of traffic for 30 minutes, then 25 %, then 100 %. A feature flag (billing_v2_engine) gates the new code path within the application, allowing instant rollback independent of the deployment.

The flag is managed in the Northline flag service (environment-dependent — staging and production have separate flag stores). ⚠️ This capability requires the flag service to be configured per environment; confirm availability before planning your release.

Database migration: expand-contract

The migration follows the expand-contract (also called parallel-change) pattern to avoid breaking the running application:

  1. Expand (deploy with old code still running): Add new columns as nullable; do not remove old columns.
  2. Migrate data: Backfill new columns in batches, never locking the table for more than a few seconds.
  3. Deploy new code: Both old and new columns exist. New code writes to new columns; old code writes to old columns.
  4. Contract (after full rollout is stable): A follow-up migration removes old columns in a separate release.

Never run destructive schema changes (DROP COLUMN, DROP TABLE) in the same deploy as application code changes. Always separate the contract step by at least one full release cycle.

Security checkpoint

Monitoring and observability

Error rate, latency P50/P99, and business metric (VAT calculation success rate) are on a shared dashboard. The SRE sets an alert threshold: if error rate rises above 0.5 % during canary window, the pipeline automatically halts further traffic shift and pages the on-call engineer.

Refer to #sad5 and #sad7 for observability principles underpinning these dashboards.

Approvals

The pipeline generates a release summary: image digest, changelog, test results, migration plan, and canary plan. The release manager reviews this summary and clicks "Approve" in the pipeline UI. No approval = no production deploy, even on a Friday afternoon.

Failure scenarios and rollback

FailureDetectionResponse
Canary error rate spikeAutomated alertHalt traffic shift; roll feature flag to off; SRE investigates
Migration script fails mid-runPipeline exit codeStop deploy; run compensating script (pre-written and tested); no code deployed
Post-deploy business metric dropSRE dashboardToggle feature flag off immediately; schedule incident review

Rollback is not a redeploy of the previous image alone — you must also consider the database state. If the expand step ran but no destructive changes were made, toggling the flag off is sufficient. If destructive changes ran, you need the compensating script. This is why the contract step is always a separate release.

Cost considerations

Canary deployments temporarily run two versions simultaneously, increasing compute cost. At Northline scale this is acceptable; at very small margins, teams sometimes accept rolling deploys instead to avoid the dual-run cost. Evaluate cost versus risk per service.

Validation

After 100 % traffic shift:


Worked examples

Example A: Rolling deployment for a stateless API

Northline's notification-service is stateless and low-risk. The team uses a rolling deploy: Kubernetes (see #devops7) replaces pods one at a time. If any pod fails its readiness probe, the rollout pauses. No manual approval is required because:

Example B: Blue-green for a scheduled batch job

The invoice-generation batch runs at 02:00 every night. The team stands up a green environment at 23:00, runs a full dry-run against a production data snapshot, gets human sign-off at 01:45, and switches the cron scheduler to point at green. Blue is kept warm until 04:00. If the 02:00 run produces incorrect totals, they switch the scheduler back to blue before any invoices are emailed.


Failure chain: anatomy of a bad deploy

Engineer pushes code Friday 16:45
  → CI passes (unit tests only, no contract tests)
  → Directly promoted to production (gate bypassed "just this once")
  → Migration runs: drops old column
  → Old pods (not yet restarted) crash: KeyError on missing column
  → No canary: 100 % of users see 500 errors
  → Rollback attempted: old image redeployed
  → Old image still crashes: column is gone
  → DBA restores from backup: 3-hour outage
  → Post-incident: gate bypass, missing contract tests, no canary identified as causes

Every step in the failure chain had a corresponding control in this lesson. None of the controls were used.


Guided exercise

Scenario: You are the platform engineer for Northline's search-service. A new ranking algorithm doubles CPU usage during peak hours. Plan its canary release.

Step 1: Define the metric that will confirm success or failure of the canary. Write it in the form: "If [metric] exceeds [threshold] during the canary window, halt and roll back."

Step 2: Decide whether you need a feature flag in addition to traffic splitting. Justify your answer.

Step 3: Write the go/no-go checklist (minimum five items) that the release manager must confirm before approving 100 % traffic shift.

Step 4: Describe what rollback looks like if the CPU spike causes pod OOM-kills at 25 % canary traffic.

Solution

Step 1: "If P99 CPU utilisation exceeds 85 % on the canary pods or if request error rate exceeds 1 % for more than two consecutive minutes, halt the canary and roll back."

Step 2: Yes. A feature flag allows instant rollback independent of the pod rollout. If the ranking algorithm produces incorrect results (a business correctness issue, not just a resource issue), the flag can be toggled off without waiting for Kubernetes to roll back pods.

Step 3: Go/no-go checklist:

Step 4: OOM-kills at 25 % canary: Kubernetes will mark pods as CrashLoopBackOff. The deployment controller stops the rollout automatically. Toggle the feature flag off. Use kubectl rollout undo to remove the canary pods. Investigate memory profile in staging before re-attempting. No database changes were involved, so no migration rollback is needed.


Independent exercise

Task: Design a deployment strategy document for a fictional Northline "Authentication v3" service that:

Acceptance criteria:


Environment parity and configuration drift

A deployment pipeline is only as trustworthy as the similarity between environments. If staging has a different database version, a different TLS certificate, or a different load balancer configuration than production, a passing staging gate is weak evidence of production readiness.

Northline enforces environment parity at three levels:

  1. Infrastructure: Staging and production use the same Terraform modules (#devops8) and differ only in resource sizes and instance counts. The structure is identical.
  2. Configuration: All environment-specific values are injected at runtime from the secrets manager (#cyber5, #cloud11). No value is baked into the image (#devops6). The same image binary runs in every environment.
  3. Data shape: Staging uses a sanitised copy of production data refreshed weekly. Tests that pass on a toy dataset but fail on real-world data volume do not reach production.

When a staging gate passes but production fails, the first question is always: "What differs between staging and production?" The answer is almost always configuration, data volume, or a resource size difference. Reducing those differences reduces surprises.

Promotion records and audit trails

Every promotion — not just production — is recorded. The pipeline writes a promotion record containing:

These records feed the change management system (#sad9) and make incident investigations dramatically faster. "When did this version reach staging?" is a one-line query, not a detective exercise through chat logs.

Promotion records are immutable append-only entries. They are never edited after the fact. If a promotion was made in error, the record stays and a reversal promotion is added.


Common mistakes

MistakeWhy it hurtsBetter approach
Skipping a gate "just this once"Creates a culture where gates are optionalAutomate the gate; make bypass require a named override with audit log
Running DROP COLUMN in the same deploy as new codeInstant rollback becomes impossibleAlways use expand-contract; separate contract step by at least one release
Treating feature flags as permanentFlag sprawl, dead code, cognitive loadSet a flag expiry date on creation; clean up within two sprints of full rollout
Canary with no business metricError rate can be fine while results are wrongAlways include at least one business-level metric in canary criteria
"Rollback" meaning "redeploy old image"Ignores database stateTest the rollback path in staging before every production deploy
Environment parity gapsStaging green, production red — no predictive powerEnforce parity at infrastructure, configuration, and data levels
No promotion recordsIncident investigations require manual reconstructionWrite immutable promotion records for every environment transition

Quick checks

Q1: What is the key operational difference between Continuous Delivery and Continuous Deployment?

A: Continuous Delivery requires a human approval before production; Continuous Deployment promotes automatically without human intervention once all automated gates pass.

Q2: In a canary deployment, what happens if the canary metric threshold is breached?

A: Traffic shift halts; the canary pods are removed or reduced; the previous version continues serving all traffic; an investigation begins before any retry.

Q3: Why should DROP COLUMN always be a separate release from the new application code?

A: The running application pods may still reference the old column. Dropping it simultaneously causes crashes that cannot be fixed by a code rollback alone, because the column no longer exists.

Q4: What does a feature flag add that traffic-based canary alone does not?

A: An instant, application-level on/off switch that can be toggled without a pod rollout or deployment change — useful for business correctness issues, not just resource spikes.

Q5: Name two items that must always appear in a go/no-go checklist.

A: A measurable automated metric threshold (e.g., error rate < X %) and a named human sign-off with an audit trail. (Any two valid items from the lesson are acceptable.)


Quiz alignment

Quiz questionLesson section
CD vs CDep distinctionPlain English
Promotion gate contentsWalkthrough → Gates
Blue-green rollback mechanicsWorked Example B
Expand-contract stepsWalkthrough → Migration
Feature flag purposePlain English, Guided exercise

Takeaways


Deployment strategy decision guide

Use this reference when choosing a strategy for a new service or a significant change:

FactorBlue-greenCanaryRolling
Rollback speedInstant (swap back)Fast (reduce canary traffic)Slower (undo pod-by-pod)
Cost during deployHigh (2× resources)Low–medium (small canary slice)Low (1 extra pod at a time)
Schema migration supportYes (keep old env warm)Yes (flag gates new code path)Risky without flag isolation
Suitable for stateless servicesYesYesYes
Suitable for stateful/batchYes (schedule switch)With careNot recommended
Business metric validationBefore full cutoverDuring phased traffic shiftPost-rollout only

This table is a starting point. The right strategy also depends on team on-call capacity (canary requires active monitoring), budget constraints (blue-green doubles compute cost temporarily), and whether the service has database migrations that constrain which strategies are safe (#sad9 change risk assessment).


Bridge to next lesson

You designed a deployment strategy and know what artifact gets promoted — a Docker image. The next lesson (#devops6) opens that image, explains how layers, multi-stage builds, and security controls inside the image affect everything from build speed to supply-chain risk. Understanding the artifact is what makes the pipeline in this lesson trustworthy.