Course contents · Lesson 10 of 16

Safe Releases: Rollbacks and Progressive Delivery

Continuous Delivery · Lesson 10 of 16 · 11 min Engineer

It is late on a Friday, version 1.5.0 went live ten minutes ago, and the checkout error graph is climbing. How do you get back? This lesson covers the ways back, when going forward is safer, why databases make undoing hard, and progressive delivery, where metrics decide whether a release keeps spreading.

Three ways to roll back

To roll back is to return users to the last version that worked. In lesson 8, blue-green and canary releases rolled back by moving traffic to the old version while it still ran. Once it is gone, there are three ways back:

Way backWhat you doSpeedWorks only if
Switch the flag offChange one setting (lesson 9)SecondsThe change is behind a flag
Redeploy the previous artifactDeploy the last good image, such as 1.4.2, againMinutesThat image is still in the registry
Revert the commitUndo it in Git; the pipeline builds and deploys the resultSlowest: a full pipeline runThe pipeline is healthy

Redeploying is quick because artifacts are immutable (lesson 6): 1.4.2 is the exact build that worked yesterday, so nothing is rebuilt. On Kubernetes, kubectl rollout undo does this (see Kubernetes Rolling Updates and Rollbacks).

A revert is a new commit that undoes the changes of an earlier one, and git revert writes it for you. You need it even after a redeploy: otherwise main still holds the bad change, and the next merge ships it again.

Two timelines of the shared main branch. Top, git revert C: commits A, B and C stay, and a new commit D, Revert new checkout, is added after C. A dashed arc says D's code equals B's code, and the pipeline builds and deploys D like any change. Bottom, git reset and force push, to avoid on shared main: C is erased from main, but teammates' copies still have C, so the histories disagree. Commit names are illustrative
The revert adds D, so the code matches B while the history keeps every step.

The aha: the code matches B again, yet C stays in the history for everyone to see. Rewriting shared history with git reset and a force push instead leaves your teammates' copies disagreeing with main.

The fastest rollback is the one you have rehearsed. An untried one tends to fail when you need it: a retention rule deleted the old image (lesson 7), or nobody remembers the command. Practise each path in staging.

Roll back or roll forward?

To roll forward is to fix a bad release by shipping a new version on top of it. Roll back by default when users are hurting and the cause is unknown: the previous version worked yesterday, while a fix written under pressure is unproven.

Roll forward when going back would do more harm: the release changed data the old version cannot read, it closed a security hole that going back would reopen, or the fix is small and tested and your pipeline is fast. The diagram puts the flag first because it is fastest, and data second because a redeploy cannot undo it.

Decision diagram. A bad release is detected. First question: can a flag switch it off? Yes: turn the flag off, in seconds with no deploy. No: has data changed so the old version would break? No: redeploy the previous artifact, in minutes. Yes: roll forward by shipping a small, tested fix. After any path, confirm the numbers recover, then find the cause, and rehearse each path in staging
The cheapest undo comes first; changed data is the case where going back stops being safe.

Why databases make rollback hard

A schema is the structure of a database: its tables and columns. Code rolls back because the old artifact still exists, but data stays as the new version left it. If 1.5.0 changed the schema by renaming the column name to full_name, redeploying 1.4.2 brings back code that reads name, which no longer exists, so its requests fail.

The expand-then-contract pattern, also called parallel change, splits one breaking change into releases that each work with the version before, so any step can be rolled back:

  1. Expand. Add the column full_name, and release code that writes both columns but still reads name.
  2. Switch. Copy existing values into full_name, then release code that reads it and still writes both.
  3. Contract. Once no version you run or might roll back to reads name, stop writing it, and later drop the column.

One rename becomes three or four releases. Only the final drop cannot be undone, which is why it comes last.

Progressive delivery: metrics decide

Lesson 8's canary needed someone to watch graphs and raise the share by hand. Progressive delivery automates that: the release reaches users in planned steps, an automated check reads metrics at each step, and the share grows only while the checks pass. A failed check sends traffic back to the stable version without waiting for a person, and the tool can then alert the team, for example in Slack.

Flowchart. Deploy v2 beside stable v1, then send 5 percent of traffic to v2. An automated metric check follows. On pass, widen to the next step, for example 25 percent, and check again at each step; when all steps pass, v2 gets 100 percent and is stable. On fail, automatic rollback sends all traffic back to v1, then the team is notified with the failing numbers. A panel says a controller such as Argo Rollouts or Flagger runs the loop, with illustrative thresholds: error rate under 1 percent, p99 latency under 500 ms, SLO on track
Every step must pass a check, and a failed check rolls back before anyone opens a dashboard.

The checks read lesson 8's error rate and p99 latency, plus SLO checks: would the canary break your service level objective, a target such as 99.9 percent of requests succeeding over 30 days (see SLI, SLO and SLA)?

A controller, a program in the cluster that keeps steering it toward what an object describes, runs the loop. Argo Rollouts adds a Rollout object that you use instead of a Deployment. This excerpt sends 5, 25, then 50 percent of traffic to the new version, pausing 10 minutes at each step:

apiVersion: argoproj.io/v1alpha1
kind: Rollout
metadata:
  name: shop
spec:
  # replicas, selector, template: as in a Deployment
  strategy:
    canary:
      analysis:              # runs in the background
        templates:
        - templateName: error-rate
      steps:
      - setWeight: 5
      - pause: {duration: 10m}
      - setWeight: 25
      - pause: {duration: 10m}
      - setWeight: 50
      - pause: {duration: 10m}

After the last step, the new version becomes stable and the old one scales down. Without a traffic router such as a service mesh, Argo Rollouts approximates weights with pod counts. The analysis is a separate object that queries Prometheus, a metrics database:

apiVersion: argoproj.io/v1alpha1
kind: AnalysisTemplate
metadata:
  name: error-rate
spec:
  metrics:
  - name: error-rate
    interval: 1m
    failureLimit: 1
    successCondition: result[0] < 0.01
    provider:
      prometheus:
        address: http://prometheus.monitoring:9090
        query: |
          sum(rate(http_requests_total{app="shop",track="canary",code=~"5.."}[5m]))
          / sum(rate(http_requests_total{app="shop",track="canary"}[5m]))

Every minute it measures the share of canary requests that failed with a 5xx server error; below 0.01 (1 percent) passes. failureLimit: 1 tolerates one failed measurement; a second fails the analysis, which aborts the rollout and sets the canary's weight to zero. The query's metric and label names are illustrative.

Flagger does the same with a Canary object: its README example raises traffic in 5 percent steps up to 50 and rolls back after 10 failed checks.

Write rollback criteria before the release

Automation helps only if someone decided, while calm, what counts as bad. Rollback criteria are those rules, written before the release:

QuestionExample answer (illustrative)
Which numbers?Canary error rate above 1 percent, or double stable's; p99 above 500 ms
How long to watch?10 minutes per step, and at least 500 requests before judging
Who decides?The controller; the on-call engineer may also roll back at any time, without asking

Compare the canary with stable, not only with a fixed limit: when both worsen together, the cause is probably something they share, such as the database.

The "who" matters most: if a rollback needs a manager's approval, people wait and hope. Let whoever is on call roll back without asking, and treat it as a normal outcome, in the blameless spirit of lesson 1.

Check yourself

After 1.5.0 breaks checkout, your team redeploys 1.4.2 but does not revert the commit. What happens at the next merge to main?

The bad change ships again, because main still contains it and every new build starts from main. Only a revert or a fix on main stops it coming back.

Release 1.5.0 dropped the column name after copying it to full_name. Why does redeploying 1.4.2 fail, and what would have avoided it?

1.4.2 reads name, which no longer exists. Expand-then-contract would have kept name until no version, including rollback targets, read it.

Mid-canary, the canary's error rate rises from 0.5 to 2 percent, and the stable version's does too. Is the release the likely cause?

Probably not: both versions got worse together, which points to something they share, such as the database. Comparing the canary with stable separates a bad release from a bad day.