How do you implement automated rollback in a deployment pipeline?

Medium Topic: CI/CD May 24, 2026

Automated rollback is triggered when post-deployment health checks fail. A robust implementation:

  1. Health check gate: After deployment, poll the health endpoint for 2-3 minutes.
  2. Metric thresholds: Monitor error rate and p99 latency for 5 minutes post-deploy.
  3. Rollback trigger: If error rate exceeds a threshold, automatically re-deploy the previous image tag.
# Generic shell rollback logic
NEW_VERSION="v2.0"
PREV_VERSION="v1.9"

deploy $NEW_VERSION
if ! health_check_passes; then
  echo "Rollback triggered"
  deploy $PREV_VERSION
  alert_pagerduty "Automatic rollback executed"
fi
← Previous Why do you use branch protection rules in... Next → How do you structure a mono-repo CI/CD pipeline...

Practice Similar Questions

Back to CI/CD Topics