Shipping safely to production is about limiting how much can go wrong at once and how fast you can undo it. Progressive delivery exposes a release gradually (blue/green switches, canary steps, feature flags, and rings of users, often across many clusters through GitOps), with automated analysis deciding whether to continue. Database migrations are the part that cannot simply be rolled back, so they follow expand and contract: make compatible changes first, move code, then remove the old shape later. Whether to roll back or roll forward depends on what changed. And the four DORA metrics (deployment frequency, lead time for changes, change failure rate, time to restore) show whether all this makes delivery faster and safer. This lesson follows one release with a schema change, and shows two failures: a destructive migration that made rollback impossible, and a "big bang" rollout to every cluster at once.
Difficulty: Master · Know this first: Lesson 191, Lesson 189
By the end of this lesson you can work at four levels:
This page teaches it with a plain-language analogy, an animated diagram with normal and failure scenarios, a simulator, a quiz, basic, intermediate, advanced, and master checks, the expert detail ("Go deeper"), a production incident, a hands-on lab with commands and their output, and a production design exercise.
This bar adds up minutes from the first migration to full rollout. It is a worked example, not a measurement. The migration and multi-cluster hops decide whether a bad release can be undone and how far it spreads.
Pick the migration style, how traffic moves, and how clusters receive the release. A bug will surface in one Region after 10 minutes.
Three questions. No score is saved anywhere — this is just you against the material.
Progressive delivery grows in four levels: separating deploy from release, migrating safely, automating rollouts, and running fleet-wide delivery with metrics.
At the basic level you can deploy and release separately.
Where it breaks: assuming a rollback is always possible.
Try it: Basic
What is the fastest way to turn off a misbehaving new feature that is already deployed everywhere?
Now do it: Put your next feature behind a flag.
At the intermediate level schema changes never break the previous version.
Try it: Intermediate
You need to rename a column used by a busy service. What are the steps?
Now do it: Write the expand and contract steps for a real rename.
At the advanced level rollouts promote and abort themselves.
Try it: Advanced
A canary step lasts 2 minutes, but errors show up after cache warm-up at 10 minutes. What do you change?
Now do it: Check the timing of your rollout steps.
At the master level releases move through many clusters safely, and you can show the effect.
Trade-off: rings slow the fleet-wide rollout from minutes to hours; that time is what limits a bad release to one cluster.
Try it: Master
Why should DORA metrics not be used to rank teams?
Now do it: Plot one service's DORA metrics over a quarter.
A canary with Argo Rollouts and an analysis template that compares error rates from Prometheus; the rollout aborts and returns traffic to the stable version on failure (check the Argo Rollouts documentation for your version).
apiVersion: argoproj.io/v1alpha1
kind: Rollout
metadata: {name: exports}
spec:
strategy:
canary:
steps:
- setWeight: 5
- pause: {duration: 20m}
- analysis: {templates: [{templateName: error-rate}]}
- setWeight: 25
- pause: {duration: 20m}
- analysis: {templates: [{templateName: error-rate}]}
---
apiVersion: argoproj.io/v1alpha1
kind: AnalysisTemplate
metadata: {name: error-rate}
spec:
metrics:
- name: errors
interval: 1m
count: 10
failureLimit: 2
successCondition: result[0] < 0.01
provider:
prometheus:
address: http://prometheus.monitoring:9090
query: sum(rate(http_requests_total{app="exports",code=~"5..",rollout="canary"}[2m])) / sum(rate(http_requests_total{app="exports",rollout="canary"}[2m]))
Expand and contract for renaming customer_id to customer_ref in PostgreSQL:
-- release N (expand): additive, the old version still works ALTER TABLE orders ADD COLUMN customer_ref text; -- nullable: no table rewrite CREATE INDEX CONCURRENTLY orders_customer_ref_idx ON orders (customer_ref); -- application writes both columns, reads customer_ref with a fallback to customer_id -- backfill in small batches, outside peak hours: UPDATE orders SET customer_ref = customer_id WHERE id IN (SELECT id FROM orders WHERE customer_ref IS NULL LIMIT 10000); -- release N+1: reads and writes only customer_ref -- release N+2 (contract), after no queries touch customer_id for a week: ALTER TABLE orders DROP COLUMN customer_id;
This is a composite of a failure pattern that keeps repeating; the details are illustrative. The rename that removed the way back.
orders.customer_id to customer_ref in place, then v215 rolls out to 100%.Migrations are reviewed for backward compatibility (a CI job runs the previous version's tests against the new schema), renames and drops follow expand and contract over several releases, and release plans state whether rollback is possible.
Everything here runs on any Linux machine: your own laptop, WSL on Windows (run wsl --install in PowerShell once), or a small cloud VM. The Python needs only Python 3 and its standard library; check that you have it with python3 --version.
Before you start: Linux with sqlite3 (sudo apt install sqlite3) and Python 3.
Type each one, read what it prints, and compare it with the note above it.
Make a table that the current release (v214) reads by its old column name.
mkdir -p ~/labs/pd && cd ~/labs/pd && rm -f app.db
sqlite3 app.db "CREATE TABLE orders(id INTEGER PRIMARY KEY, customer_id TEXT); INSERT INTO orders(customer_id) VALUES ('c1'),('c2');"
sqlite3 app.db "SELECT id, customer_id FROM orders;" # v214's queryExpand: add the new column and backfill; the old query still works, so v214 can still run.
sqlite3 app.db "ALTER TABLE orders ADD COLUMN customer_ref TEXT; UPDATE orders SET customer_ref = customer_id WHERE customer_ref IS NULL;" sqlite3 app.db "SELECT id, customer_id FROM orders;" # v214 still works sqlite3 app.db "SELECT id, customer_ref FROM orders;" # v215 reads the new column
Compare with a destructive rename: the old version breaks at once.
cp app.db rename.db sqlite3 rename.db "ALTER TABLE orders DROP COLUMN customer_ref; ALTER TABLE orders RENAME COLUMN customer_id TO customer_ref;" sqlite3 rename.db "SELECT id, customer_id FROM orders;" # v214 after a rename
release.pyThis program checks which application versions can run against each schema state of a rename done in place and done by expand and contract, so you can see where rollback stays possible. Then it computes the four DORA metrics from a month of deploy and incident records. Save it as release.py, then run it.
# release.py
from datetime import datetime, timedelta
READS = {"v214": {"customer_id"}, "v215": {"customer_ref"}}
PLANS = {
"rename in place": [("before", {"customer_id"}), ("after rename", {"customer_ref"})],
"expand and contract": [("before", {"customer_id"}), ("expanded", {"customer_id", "customer_ref"}),
("contracted (2 weeks later)", {"customer_ref"})],
}
for plan, states in PLANS.items():
print(plan)
for name, columns in states:
ok = [v for v, needs in READS.items() if needs <= columns]
print(f" {name:<28} runs: {', '.join(ok) or 'nothing'}")
print()
t0 = datetime(2026, 11, 1, 9)
DEPLOYS = [ # (committed, deployed, caused a failure?, restored after minutes)
(t0 + timedelta(days=d, hours=-6), t0 + timedelta(days=d), d in (2, 15), 20 if d == 2 else 45)
for d in range(0, 28) if d % 7 not in (5, 6)
]
days = 28
freq = len(DEPLOYS) / days
lead = sorted((dep - com).total_seconds() / 3600 for com, dep, _, _ in DEPLOYS)
failures = [d for d in DEPLOYS if d[2]]
print(f"deployment frequency {freq:.1f} a day ({len(DEPLOYS)} in {days} days)")
print(f"lead time for changes median {lead[len(lead) // 2]:.0f} h")
print(f"change failure rate {len(failures) / len(DEPLOYS):.0%}")
print(f"time to restore median {sorted(f[3] for f in failures)[len(failures) // 2]} min")
Run it, and you should see this output:
$ python3 release.py rename in place before runs: v214 after rename runs: v215 expand and contract before runs: v214 expanded runs: v214, v215 contracted (2 weeks later) runs: v215 deployment frequency 0.7 a day (20 in 28 days) lead time for changes median 6 h change failure rate 10% time to restore median 45 min
The same Linux steps, made into a real script you can keep and run again. It uses the Bash features a production script needs: functions (one per step), an array of step names, arguments to choose steps, a case for options, exit codes recorded for each step, and a trap that prints a summary even when you stop it with Ctrl+C. Make a folder for this lesson (mkdir -p ~/labs/progressive-delivery-database-migrations-and-dora-metrics && cd ~/labs/progressive-delivery-database-migrations-and-dora-metrics) and save this as lab.sh.
#!/usr/bin/env bash
# The Linux steps of "Progressive Delivery, Safe Database Migrations, and DORA Metrics", as one script (save it as lab.sh).
#
# ./lab.sh run every step, in order
# ./lab.sh 2 4 run only steps 2 and 4
# ./lab.sh --list list the steps
#
# The steps share one shell, so a later step can use what an earlier one set up (a folder,
# a variable, a container): run them all in order the first time. Your own scripts should
# start with "set -euo pipefail"; this one runs teaching commands, and some of them fail on
# purpose, so it records each step's exit code instead of stopping at the first failure.
STEPS=(
'Make a table that the current release (v214) reads by its old column name.'
'Expand: add the new column and backfill; the old query still works, so v214 can still run.'
'Compare with a destructive rename: the old version breaks at once.'
)
step_1() {
mkdir -p ~/labs/pd && cd ~/labs/pd && rm -f app.db
sqlite3 app.db "CREATE TABLE orders(id INTEGER PRIMARY KEY, customer_id TEXT); INSERT INTO orders(customer_id) VALUES ('c1'),('c2');"
sqlite3 app.db "SELECT id, customer_id FROM orders;" # v214's query
}
step_2() {
sqlite3 app.db "ALTER TABLE orders ADD COLUMN customer_ref TEXT; UPDATE orders SET customer_ref = customer_id WHERE customer_ref IS NULL;"
sqlite3 app.db "SELECT id, customer_id FROM orders;" # v214 still works
sqlite3 app.db "SELECT id, customer_ref FROM orders;" # v215 reads the new column
}
step_3() {
cp app.db rename.db
sqlite3 rename.db "ALTER TABLE orders DROP COLUMN customer_ref; ALTER TABLE orders RENAME COLUMN customer_id TO customer_ref;"
sqlite3 rename.db "SELECT id, customer_id FROM orders;" # v214 after a rename
}
# print a step that has to be run by hand, instead of running it
by_hand() {
echo " (run this one yourself: $1)"
sed 's/^/ /'
}
RESULTS=()
run_step() {
local n=$1 start=$SECONDS code
printf '\n== step %d of %d: %s\n' "$n" "${#STEPS[@]}" "${STEPS[n-1]}"
"step_$n"
code=$?
RESULTS+=("step $n: exit code $code, $((SECONDS - start)) s")
}
summary() {
echo
echo "== summary"
local r
for r in "${RESULTS[@]}"; do echo " $r"; done
}
case "${1:-}" in
-h|--help) sed -n '2,6p' "$0"; exit 0 ;;
--list) for i in "${!STEPS[@]}"; do echo "$((i + 1)). ${STEPS[i]}"; done; exit 0 ;;
esac
[ $# -eq 0 ] && set -- $(seq 1 "${#STEPS[@]}")
for n in "$@"; do
if ! [[ $n =~ ^[0-9]+$ ]] || (( n < 1 || n > ${#STEPS[@]} )); then
echo "there is no step '$n'; try --list" >&2
exit 2
fi
done
trap summary EXIT
trap 'echo; echo "stopped with Ctrl+C"; exit 130' INT
for n in "$@"; do run_step "$n"; done
Then make it executable and run it:
chmod +x lab.sh ./lab.sh --list # the steps ./lab.sh # every step, then a summary of exit codes and times ./lab.sh 2 3 # only steps 2 and 3
New to a feature used above? These W3Schools pages explain each one from zero, with examples you can run in the browser.
mkdir, rm, cp, cd, If...Else.A company deploys to 8 Kubernetes clusters in 4 Regions with GitOps, releases weekly, and had two releases last quarter that could not be rolled back. Design its progressive delivery process.
How are schema changes made safely? How does traffic move to a new version, and what decides promotion? How are features released? In what order do clusters receive a release? How do you choose rollback or roll forward? Which metrics show improvement?
Say 30 services, 8 clusters, 4 Regions, weekly releases, a 6% change failure rate, and 2 hours average time to restore.
Expand and contract for every schema change, with a CI job running the previous version against the new schema; Argo Rollouts canaries with analysis on errors, latency, and a business signal per service; feature flags for user-visible behaviour, with owners and expiry; GitOps rings (a canary cluster, one Region, the rest) with automated promotion after analysis; release plans stating rollback or roll-forward; daily releases once rings and analysis are trusted; DORA metrics per service reported monthly as trends.
Expand and contract spreads one change over several releases; rings and analysis slow fleet-wide rollout to hours; flags add code paths to clean up; all of it lowers change failure rate and time to restore, which is what allows deploying more often.
Each row is one way this system went wrong in the diagram's scenarios. The hop number is where to look first.
| Scenario | Where | Effect | What goes wrong |
|---|---|---|---|
| Destructive migration | Hop 1: Expand migration | Breaks | The migration renames customer_id to customer_ref in place. v215 starts; a bug in its new export code corrupts some exports. Rolling back to v214 fails immediately: v214 queries customer_id, which no longer exists. Renaming back would break v215 mid-flight. |
| Every cluster at once | Hop 6: Multi-cluster rings | Breaks | All six clusters track the same version in the GitOps repository, so merging v215 syncs everywhere within a minute. A configuration value valid in the test Region is wrong in production Regions; every Region fails together. |
The official documentation and standards behind this lesson. Versions and defaults change; when a command or field here differs from them, trust the official page.
Last updated . Next review due by November 2027. Found something out of date? Tell me.