LESSON 6

Deployment Strategies

Choose how to change what is running: recreate, rolling, blue-green, and canary deployments, database migrations that allow rollback, verification, and automated and manual rollback.

Introduction

A deployment is the riskiest routine thing a team does. Every deployment replaces something that works with something that should work better. The question is not whether a deployment will ever go wrong but how much damage it can do, how quickly you will notice, and how fast you can undo it.

Deployment strategies are different answers to those questions. This lesson covers the main ones, the special problem of the database, and how to make rollback routine.

Learning Objectives

  • Compare recreate, rolling, blue-green, and canary strategies, and choose among them.
  • Use feature flags to separate deployment from release.
  • Apply the expand and contract pattern to database changes so that rollback stays possible.
  • Define verification and automatic rollback criteria.
  • Write and practice a rollback procedure.
  • Handle workers, queues, and external dependencies during deployment.
  • Use AI to review deployment plans and rehearse failures.

1. The Questions Every Strategy Answers

Question Why it matters
Is there downtime? User impact
What share of users sees the new version first? Blast radius
How fast can we detect a problem? Time to notice
How fast can we go back? Time to restore
What does it cost (extra capacity, complexity)? Trade-off
Do old and new versions run side by side? Compatibility requirements

2. The Strategies

Strategy How it works Pros Cons
Recreate Stop the old version, start the new Simplest; no version overlap Downtime
Rolling Replace instances gradually, a few at a time No downtime; no extra capacity beyond a margin Old and new coexist; slow rollback
Blue-green Run the new version (green) beside the old (blue); switch traffic at once Instant rollback by switching back; easy pre-switch testing Double capacity; data and sessions must be compatible with both
Canary Send a small share of traffic to the new version, increase while metrics stay healthy Smallest blast radius; real-traffic validation Needs traffic routing, good metrics, and time
Feature flag release Deploy code dark; enable per user group Decouples deploy and release; instant off Flag management; untested combinations

These combine. A common arrangement: rolling or canary deployment of the artifact, with new behavior behind a feature flag that is enabled gradually.

Choosing for SignalDesk’s pilot:

  • API and web app: rolling deployment with readiness checks, because the load is modest and it needs no extra capacity. Move to canary when traffic and monitoring justify it.
  • Worker: a graceful drain, so that in-flight imports finish or are safely re-queued (idempotent jobs from the quality course), then replace.
  • AI summaries: behind a feature flag, enabled gradually, with an instant off switch.
  • Database: expand and contract migrations (below), applied before the code that needs them.

Record the choice and the reasons as an ADR.

3. Compatibility During a Deployment

In rolling and canary deployments, old and new versions run together against the same database and queue for some time. Every change must be compatible in both directions during that window:

  • The new API version must work with data written by the old version, and vice versa.
  • Messages put on the queue by the old version must be understood by the new worker, and the reverse.
  • API changes must be backward compatible for clients (API versioning policy from the documentation course).
  • Cached or stored formats must be readable by both versions.

If a change cannot be made compatible, split it into several deployments, or use a different strategy (a short recreate window with a maintenance notice may be the honest answer for a rare, large change).

4. Database Changes: Expand and Contract

The database is the hard part because data does not roll back when code does. The safe pattern is to make schema changes additive first, destructive last, across several releases.

Example: rename the column body to content.

1
2
3
4
5
Release 1  EXPAND:   add column `content`; code writes to both columns,
                     reads from `body`
Backfill:            copy `body` into `content` for existing rows
Release 2  MIGRATE:  code reads from `content` (still writes both)
Release 3  CONTRACT: stop writing `body`; later, drop `body`

At each step the previous code version still works, so rolling back the application is safe. Rules:

  • Separate migration from code deployment in the pipeline: apply the migration, verify, then deploy code.
  • Make migrations backward compatible with the running version.
  • Avoid long locks: create indexes concurrently, backfill in batches, and avoid rewriting large tables in one step.
  • Test migrations on realistic data in staging, including timing (the quality course’s migration rehearsal).
  • Take and verify a backup before risky migrations, and know the restore time.
  • Destructive steps (dropping columns or tables) come last, after a safe waiting period, and are never bundled with the release that stops using them.
  • Have a rollback or forward-fix plan for each migration: reversible migrations where possible; otherwise a tested forward fix.

5. Verification

A deployment is not done when the command finishes. It is done when you know it works.

Automated verification:

  • Readiness and health checks pass on new instances before they receive traffic.
  • Smoke tests exercise the critical journeys against the deployed version (the quality strategy’s small end-to-end set): sign in, upload a small CSV, see it listed, read a summary.
  • Synthetic checks keep running after deployment.
  • Metrics comparison: error rate, latency, queue depth, and import failure rate for the new version compared with the old, over a defined window.

Decision rules written in advance:

1
2
3
4
5
6
Proceed to the next step if, for 10 minutes (illustrative):
  - error rate is no more than 1% above baseline
  - p95 latency is no more than 20% above baseline
  - no new error class appears in logs
  - import job failure rate is unchanged
Otherwise: stop, roll back, and notify the release owner.

Writing the rules beforehand removes the temptation to rationalize a bad signal during a stressful moment.

6. Rollback

Rollback must be easy, fast, and practiced.

Situation Typical rollback
Application bug, no schema change Redeploy the previous artifact by digest
Blue-green Switch traffic back to the previous environment
Canary Route all traffic to the stable version
New feature misbehaves Turn off the feature flag
Schema change incompatible with old code Forward fix, or restore from backup (last resort)
Bad configuration Revert the configuration change through the pipeline

Prepare:

  • A one-command or one-click rollback that uses the previous known-good artifact, still available in the registry.
  • A written procedure with who decides, how, and who is told.
  • A rollback criterion agreed in advance.
  • A practice run in staging, and occasionally a game day. A rollback that has never been tried is a hope.
  • A forward-fix option: sometimes the fastest safe action is a small fix rather than a rollback; decide quickly, but pick one.

Rolling back is normal and not a failure. Teams that treat it as embarrassing delay it, and make incidents worse.

7. Workers, Queues, and Third Parties

  • Workers: stop taking new jobs, finish or release the current one, then terminate. Jobs must be idempotent and retryable.
  • Queues: messages in flight during deployment must be processed by a compatible version. Version message formats, and tolerate unknown fields.
  • Scheduled jobs: ensure that only one version runs a schedule, so that tasks do not run twice or never.
  • External dependencies: a model provider change or outage is not fixed by rollback. Keep timeouts, fallbacks, and a kill switch.
  • Sessions and caches: ensure users are not logged out or served incompatible cached data by a switch.
  • Zero-downtime is a design property: it requires graceful shutdown, readiness checks, compatible versions, and connection draining. It does not come from the strategy name alone.

8. Deployment Windows and Communication

  • Deploy small and often during working hours with the team present, rather than rarely and late on Friday. Frequent small deployments are safer than rare large ones.
  • Tell stakeholders what is happening: an internal notice for a deployment; a customer notice only for changes that affect them.
  • Keep a deployment log (what, when, who, and result), automatically produced by the pipeline.
  • Where a freeze period is needed (a customer demo, a holiday), define it explicitly and keep it short.

9. Using AI for Deployment Planning

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
Act as a release engineer reviewing a deployment plan.

Inputs:
- The change summary (code, migrations, configuration, flags): [paste]
- Architecture deployment view and the chosen strategy: [paste]
- Current monitoring metrics available: [paste]
- Existing rollback procedure: [paste]

Tasks:
1. List what can go wrong at each step, with likelihood and impact.
2. For each migration, state whether the previous code version still
   works after it, and what would block a rollback.
3. Identify incompatibilities while old and new versions coexist
   (API, queue messages, data formats).
4. Propose verification checks and decision thresholds, marking them
   as proposals to be calibrated.
5. Write the rollback procedure for each failure type, and list what
   cannot be rolled back.
6. List the questions the release owner should answer before
   starting.

Do not assume monitoring or capabilities not listed. Mark assumptions.

Use AI to run tabletop exercises: describe a failure scenario (“the migration locks the feedback table for twenty minutes”) and ask for the sequence of decisions and what the team should check. Compare its answers with your actual runbook, and fix the runbook where it lacks an answer. Do not rely on the model to know your system’s real behavior.

10. Practical Exercise

For SignalDesk (or your project):

  1. Choose a deployment strategy per component, with reasons, and record an ADR.
  2. Implement the strategy in the pipeline for staging, including readiness gating, smoke tests, and automatic stop on failure.
  3. Write the deployment verification rules with thresholds.
  4. Redesign one real schema change (for example, renaming a column) as expand and contract across three releases, and rehearse it on realistic data in staging, with timing.
  5. Make the worker shut down gracefully, and test deployment during a running import.
  6. Write the rollback procedure for each failure type, and practice it in staging, recording the time taken.
  7. Put AI summary generation behind a feature flag and practice turning it off.
  8. Run the AI planning review and tabletop prompts, verify the findings, and update your procedures.

Verification

You are ready to continue when:

  • Each component has a deployment strategy and reasons, recorded as a decision.
  • Old and new versions can run side by side against the same data and queues.
  • Migrations follow expand and contract, with timing tested on realistic data.
  • Verification rules and rollback criteria were agreed before deployment.
  • A rollback has been practiced end to end, and its duration is known.
  • Deploying during an active import does not lose or duplicate data.

Key Takeaways

  • A strategy defines blast radius, detection time, and recovery time; choose by risk and capability.
  • Old and new versions coexist during a deployment, so every change must be compatible both ways.
  • Change the database additively first and destructively last, so that rollback stays possible.
  • Write verification and rollback rules in advance, and practice rollback until it is routine.
  • AI can enumerate failure modes and run tabletop exercises; the release owner decides.

What’s Next?

Deployment is the mechanism. Release is the decision and the communication around it. Next, we plan releases: scope, readiness criteria, risk, coordination, and the human conversation about when to ship.