DevOps · Operations

Rollback Strategies

Every deployment needs a way back. Fast, practised rollback turns a bad release into a minor incident.

Advanced 5 min Lesson 26 of 30
Before you start:Deployment Strategies
0/30 in DevOps
On this page · 5 min · Advanced

Learning objectives#

  • Roll back by redeploying a previous version
  • Use platform rollback features
  • Decide between rollback and roll-forward
  • Keep databases rollback-safe

Explanation#

Because each release is an immutable versioned artifact, rolling back means deploying the previous version.

Platforms help: App Service slot swap back, kubectl rollout undo, ECS deployment circuit breaker with automatic rollback.

Roll forward (ship a quick fix) when rollback is risky, e.g. after a data migration.

Database changes must work with both versions (expand/contract), or rollback becomes impossible.

Code example: Three ways back#

ShellThree ways back Illustrative
# Kubernetes: return to the previous ReplicaSet
kubectl rollout history deployment/shop-api -n shop
kubectl rollout undo deployment/shop-api -n shop


# Azure App Service: swap production back with staging (the previous version)
az webapp deployment slot swap -g rg-shop -n app-shop-api --slot staging


# Any platform: redeploy the last good tag through the pipeline
gh workflow run release.yml -f version=v1.4.0
Expected output
Each command restores the last known good version in under a minute without rebuilding anything.

This example is illustrative. Copy or download it and run it in your own environment; the expected output is shown above.

Step-by-step explanation#

  1. rollout history lists previous revisions.
  2. rollout undo switches back to the previous one.
  3. Swapping slots again restores the old production build.
  4. A pipeline with a version input redeploys any earlier tag.

Real-world use case#

An alert fires five minutes after release; the on-call engineer runs one command from the runbook and service is restored.

Common mistakes#

Never practising rollback

The first time should not be during an outage. Rehearse it.

Destructive migrations in the same release

Dropping columns makes rollback impossible. Contract in a later release.

Best practices#

  • Immutable, versioned artifacts
  • One-command rollback in the runbook
  • Automatic rollback on failed health checks
  • Backward-compatible database changes

Remember this#

Rollback = deploy the previous artifact.

undo / swap back / redeploy tag.

Practise before you need it.

Practice exercise#

Your task: When is rolling forward better than rolling back?

Show solution
Text Illustrative
When the release ran an irreversible data migration, or the fix is tiny and well understood — reverting could cause more harm.

Mini quiz#

Rollback Strategies quizMultiple choice Question 1 of 1

Which command rolls back a Kubernetes Deployment?

Score so far: 0/0

Want more? Practise all DevOps MCQs · DevOps interview questions

My notes#

Saved in this browser.

Progress is saved in this browser. Sign in to sync.