Lesson 5 of 5 Deployment Strategies

Designing a Resiliency Strategy for Deployment

This lesson explains how to detect a bad release and recover with little manual effort.

Learning outcomes

After completing this lesson, you will be able to:

  • Explain health-driven promotion.
  • Compare rollback and roll forward.
  • Limit blast radius across regions.
  • Make pipeline steps resilient.

What resiliency means in deployment

A release can fail for many reasons, from a defective build to a transient network error. A resilient process assumes that this will happen, and aims to limit the blast radius, which is how many users are affected, and to shorten the time to recovery.

Detecting failure

Automatic recovery depends on reliable detection. A deployment should be judged by health signals, not merely by whether the deployment task exited successfully. Useful signals include health endpoints, error rates and latency from Application Insights, and Azure Monitor alerts. Post-deployment verification runs after traffic moves: in a deployment job, the postRouteTraffic hook is the natural place, and it can run a smoke test or watch telemetry for a defined period.

Azure Pipelines can use the Query Azure Monitor Alerts check on the next stage, so that promotion stops when a metric alert fires. In GitHub Actions, a job can query metrics, or a custom deployment protection rule can evaluate them.

True or false

Judging a release by health

Exam skills 3.4.5

Check how resilient deployments detect failure.

Log in to try this activity Interactive activities are free with an account.

Recovery options

Roll back

Rollback restores the previous version. It is quick and familiar, and it is safest where the release made no irreversible change. Deployment jobs can hold rollback steps in an on: failure hook, and a pipeline can redeploy a previous artifact. This is why old artifacts must be retained.

Roll forward

Roll forward ships a new fix through the pipeline. It is preferable when rollback is impossible, such as after a database change that cannot be reversed, or when the fix is small and the pipeline is fast.

Traffic and flag changes

Moving traffic away from a failed slot or region, or switching off a feature flag, avoids any deployment at all, and these are usually the fastest options.

strategy:
  runOnce:
    deploy:
      steps:
        - script: ./deploy.sh
    routeTraffic:
      steps:
        - script: ./swap-slots.sh
    postRouteTraffic:
      steps:
        - script: ./verify-health.sh
    on:
      failure:
        steps:
          - script: ./swap-slots.sh   # swap back to the previous version
      success:
        steps:
          - script: ./record-release.sh

The following diagram follows a deployment job's lifecycle hooks through a release that rolls back automatically.

Automatic rollback with deployment job lifecycle hooks. The release deploys to the staging slot; routeTraffic swaps it into production; postRouteTraffic reads Application Insights failure rates for several minutes; and if that verification fails, on: failure swaps back without an engineer.
The hooks are those of a runOnce deployment job.

Limiting blast radius across regions

Multi-region applications should never update all regions at once, as a defect would then remove the redundancy that protects them. A safe release updates one region at a time, or in small sets, with a bake time between them. Azure Front Door or Traffic Manager can drain a region before an update. Azure paired regions and availability zones offer a useful model. A pipeline can express this with a stage for each region, and with a template, so that each stage is identical apart from parameters.

stages:
  - ${{ each region in parameters.regions }}:
    - stage: Deploy_${{ region }}
      jobs:
        - template: deploy-region.yml
          parameters:
            region: ${{ region }}

The each keyword expands the list at compile time into one stage per region. Since stages run in sequence by default, regions deploy in order.

Scenario questions

Releasing across regions

Exam skills 3.4.5

Design a release that protects multi-region redundancy.

Log in to try this activity Interactive activities are free with an account.

Making pipelines resilient

The pipeline itself must also survive failure.

  • Idempotence: running a step twice gives the same result, so a retry is safe. Bicep deployments and declarative Kubernetes manifests are naturally idempotent.
  • Retries: transient failures can be handled with retryCountOnTaskFailure on an Azure Pipelines step, or with retry loops in a script. Retries should not hide real defects.
  • Timeouts: timeoutInMinutes and timeout-minutes stop a stuck step from holding resources indefinitely.
  • Dependencies under your control: an upstream feed and a private registry keep a release working when a public service is down.
  • Rerun of failed stages: Azure Pipelines can retry a failed stage, and GitHub can re-run failed jobs, so successful work need not be repeated.
Match the pairs

Resilience settings

Exam skills 3.4.5

Match each pipeline resilience practice with what it provides.

Log in to try this activity Interactive activities are free with an account.
Worked example

Automating recovery

An App Service application deploys to a staging slot and swaps into production. Sometimes a release passes all tests, but it fails with real traffic, and an engineer must swap back manually, which takes 20 minutes. How can this be automated?

Use a deployment job with the swap in routeTraffic, a health verification in postRouteTraffic that reads Application Insights failure rates for several minutes, and a swap back in on: failure. If verification fails, rollback runs automatically. More pre-release testing may reduce failures, but it does not answer the need for recovery. A manual approval after the swap would keep a person in the loop, which the scenario wants to remove.

Check yourself

When is rolling forward preferable to rolling back?

Show answer

When rollback is not possible, such as after an irreversible database change, or when a small fix can move quickly.

Exam Tips

Remember for the exam

  • Judge a release by health signals, not by the task's exit code.
  • Rollback restores; roll forward ships a fix when rollback is not possible.
  • Use on: failure hooks to automate rollback in deployment jobs.
  • Deploy one region at a time, with bake time between regions.
  • Idempotent steps make retries safe.