Skip to main content
Cloud DevOps Solutions
Get a quote Talk to an engineer

CI/CD Pipelines

Automated Rollback on Failed Deployments: Detect Fast, Revert Safely

Automated rollback detects a failed deployment through health checks or metrics and returns the service to the last known good version without waiting for a person. We combine readiness probes, post-deploy verification and a defined revert mechanism, such as Helm rollback or a Git revert, and test the whole path before relying on it.

Key takeaways

  • A rollback you have never exercised is a hope, not a control. We test it as part of delivery.
  • Detection quality decides everything: a rollback trigger needs signals that are fast, specific and not noisy.
  • Database migrations are the hard part. Backward-compatible changes make rollback possible; destructive ones do not.
  • Rolling forward with a fix is sometimes safer than rolling back, and the pipeline should support both.
  • Every automated rollback notifies the team and records why it happened.

The deploy that fails at 4:50 on a Friday

Every team eventually ships a bad release. What separates a five minute blip from a two hour incident is not whether the bug existed, but how quickly the system returns to a working state. If the answer is “someone finds the previous version, remembers the right commands and hopes the config still matches”, the response is slow and stressful.

Automated rollback makes recovery a designed behaviour of your CI/CD pipeline instead of an improvisation. This page explains how we build it, including the awkward cases such as database changes, where rollback is not as simple as it sounds.

What good looks like

  • Fast, reliable detection. The pipeline knows within minutes whether a release is healthy, using signals that distinguish real failure from noise.
  • A precise target. The last good version is identified by immutable digest or revision, not by latest.
  • A tested revert. The mechanism has been exercised against a deliberately broken release.
  • Backward-compatible data changes. The previous version can run against the current schema.
  • Visibility. Every automatic rollback produces an alert and a record stating what failed.
  • A fallback to humans. Ambiguous situations escalate rather than guessing.

How it works in practice

Layer one: the platform stops bad rollouts

Kubernetes already provides the first layer. A rolling update only terminates old pods as new ones become ready, so a version that crashes on startup or never passes its readiness probe never receives traffic, and the rollout stalls. Setting maxUnavailable conservatively and defining proper readiness probes is the foundation, and many teams have probes that do not test anything meaningful. We review them as part of the work.

If the rollout stalls, progressDeadlineSeconds marks it as failed, and the pipeline can then act on that status.

Layer two: the pipeline verifies and reverts

After deployment, the pipeline should wait for the rollout, run smoke tests, and revert if either fails. With Helm, the --atomic flag does the core of this:

helm upgrade --install checkout ./charts/checkout \
  --namespace shop \
  --set image.tag="$IMAGE_DIGEST" \
  --atomic \
  --timeout 5m \
  --history-max 10

With --atomic, Helm waits for resources to be ready and, if the upgrade fails or times out, rolls back to the previous release automatically. That covers startup failures. It does not cover a release that starts cleanly but misbehaves, which is why a post-deploy smoke test step follows:

./smoke-test.sh https://staging.example.com || {
  helm rollback checkout 0 --namespace shop --wait
  exit 1
}

Revision 0 in helm rollback means the previous revision. We prefer explicit smoke tests that exercise a real user path (log in, create a record, read it back) over a generic ping, because a service can return HTTP 200 on its health endpoint and still be broken.

Layer three: progressive delivery

For higher-risk services, canary releases limit exposure. A tool such as Argo Rollouts or Flagger sends a small share of traffic to the new version and queries Prometheus for error rate and latency. If the metrics exceed thresholds, the rollout aborts and traffic returns to the stable version automatically, with no one watching a dashboard. Well-written alerting rules double as analysis queries. This approach suits services with enough traffic to measure; a low traffic service may never produce a statistically meaningful signal in the canary window.

Blue-green deployment is the simpler alternative: run both versions, switch traffic, and switch back if needed. It costs double capacity during the release but gives the fastest reversal.

GitOps rollbacks

With a GitOps controller such as Argo CD, the desired state lives in Git. Rollback is a revert commit, which the controller applies. This is slower than an in-cluster undo but fully audited, and it avoids the trap where someone rolls back in the cluster and the controller immediately redeploys the bad version. Our GitOps tutorial for EKS shows the model, and the Helm and Argo CD deployment page covers how rollbacks fit in.

The hard part: data

Code rolls back easily. Data does not. If a release drops a column, renames a table or rewrites records, the old code may fail against the new schema, and no deployment tool can undo the lost data.

The accepted approach is expand and contract:

  1. Expand: add the new column or table without removing anything. Old and new code both work.
  2. Migrate: deploy code that writes to both and reads from the new structure.
  3. Contract: in a later release, once rollback of the earlier code is no longer plausible, remove the old structure.

This discipline is the single biggest factor in whether automated rollback is safe. Where destructive migrations are unavoidable, we mark those releases as non-rollbackable, take a backup beforehand (see backup and disaster recovery) and require approval.

Decisions and trade-offs

Roll back or roll forward. If the fix is a one-line change that you understand and the pipeline takes ten minutes, rolling forward can be quicker and avoids reverting unrelated changes bundled in the release. The pipeline should support both without drama.

Automatic versus approved rollback. Hard failures (pods never ready, smoke test fails) are safe to automate. Soft failures (error rate rises a little) are riskier, because noise can trigger needless reverts or flapping. We start with automation on hard signals and widen it as trust grows.

Cost. Canary and blue-green approaches add complexity or capacity. For a small service with modest traffic, --atomic plus smoke tests is often enough. We say so rather than selling progressive delivery everywhere.

Common failure modes

  • Useless readiness probes that always return success.
  • Rollbacks never tested, which fail the first time they matter.
  • Configuration not versioned with the code, so the old image runs with new settings.
  • Flapping, where a noisy metric triggers repeated rollbacks.
  • Silent rollbacks that nobody notices, so the same broken change is redeployed.
  • Mutable tags like latest, which make “previous version” ambiguous.

Delivery and handover

We define failure signals with your team, implement detection and revert for each deploy target, and rehearse in staging with a deliberately broken release, including a database scenario. Rollback events post to your chat channel, as described in deployment notifications. You receive a runbook covering automatic behaviour and the manual commands for when automation is the wrong tool.

How to tell it is working

Track mean time to restore for deployment failures, the share of failed releases recovered automatically, change failure rate, and the number of rollback rehearsals completed per quarter. A falling time to restore with a stable or lower failure rate is the outcome to look for. To discuss your release process, book a consultation.

References

How we deliver it

  1. 01

    Define what failed means

    We agree measurable failure signals: failed readiness, error rate, latency or crash loops, and the time window for judging them.

  2. 02

    Record the last good version

    Releases are versioned by immutable image digest or chart revision, so there is a precise target to return to.

  3. 03

    Add post-deploy verification

    Smoke tests and health checks run automatically after each deploy and gate completion of the release.

  4. 04

    Implement the revert path

    Helm rollback, Kubernetes rollout undo, Argo Rollouts analysis or a Git revert is wired to the failure signal.

  5. 05

    Handle data changes

    Migrations are made backward-compatible using expand and contract, so the previous version still works against the new schema.

  6. 06

    Rehearse and report

    We deliberately deploy a broken release in staging to prove rollback works, and set up alerts that explain every automatic revert.

Tools and technologies

HelmKubernetes DeploymentsArgo CDArgo RolloutsPrometheusFlaggerGitHub ActionsGitLab CISlackTerraform

Frequently asked questions

What is automated rollback in CI/CD?
Automated rollback is a mechanism that detects a failing deployment and restores the previous working version without manual intervention. Detection typically uses readiness probes, smoke tests or metrics such as error rate. The restore uses a versioned artefact and a revert command or Git change that has been tested in advance.
How does Kubernetes roll back a failed deployment?
A Deployment keeps previous ReplicaSets, so kubectl rollout undo returns to an earlier revision. A rolling update also stops advancing if new pods never become ready, which limits damage. Helm adds its own release history, and helm rollback restores a prior chart revision, including configuration.
Should we roll back or roll forward?
Roll back when the previous version is known good and the change is not coupled to irreversible data changes. Roll forward when the fix is small and understood, or when the schema has already moved on. Good pipelines make both fast, and teams decide in the moment based on risk and time.
How do database migrations affect rollback?
Schema changes can make the old application version fail against the new schema. The safe pattern is expand and contract: add new columns or tables first in a backward-compatible way, deploy code, and remove old structures in a later release. Destructive migrations should not ship in the same release as the code that depends on them.
Can rollback be fully automatic in production?
It can, if detection is trustworthy. Many teams automate rollback on hard failures such as pods never becoming ready or smoke test failure, and require a human for ambiguous metric changes. Fully automatic metric-based rollback works best with canary releases, where only a small share of traffic is exposed.

Talk to an engineer about automated rollback deployment

Book a free 30-minute call. We review your current setup and tell you honestly whether and how we can help.

Written by Saddique Khan, DevOps / SRE / Cloud Consultant Engineer. Last updated 2026-10-08.