Lesson 2 of 5 Deployment Strategies

Ordering Dependency Deployments Reliably

This lesson explains how to model a safe sequence, and how to reduce the need for one.

Learning outcomes

After completing this lesson, you will be able to:

  • Identify a safe deployment order.
  • Express order in a pipeline.
  • Verify health between stages.
  • Explain techniques that reduce ordering constraints.

Why order matters

Most systems have dependencies. A web front end calls an API, the API reads a database, and all of them rely on networks and identities that must already exist. If an application version that needs a new column is deployed before the column exists, requests fail. Pipelines must therefore express these relationships, instead of relying on someone remembering them.

A common sequence is foundational infrastructure first, then data, then back-end services, then front ends.

OrderLayerExamples
1Shared infrastructureVirtual networks, key vaults, identities
2DataDatabase schema changes
3Back-end servicesAPIs and workers
4Front endsWeb applications
5TrafficRouting changes and feature flags
Put in order

A safe release sequence

Exam skills 3.4.2

Arrange the layers of a release in the order they should deploy.

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

Expressing order in a pipeline

Stages and jobs with explicit dependencies make the sequence reliable. The following example ensures that infrastructure comes first, and that the API and web tier deploy only after the database succeeds.

stages:
  - stage: Infrastructure
  - stage: Database
    dependsOn: Infrastructure
  - stage: Api
    dependsOn: Database
  - stage: Web
    dependsOn: Api
  - stage: EnableFeature
    dependsOn:
      - Api
      - Web

Within an ARM or Bicep deployment, a similar idea applies. Resource Manager works out the order from references between resources, and it deploys unrelated resources in parallel. A symbolic reference in Bicep creates an implicit dependency, and dependsOn is needed only when there is no such reference. For multiple repositories, a pipeline resource trigger or workflow_run event can start a downstream pipeline after an upstream one finishes.

The following diagram compares parallel stages with a dependency.

Removing the race between the application and its database migration. In parallel stages the new code can run before the migration finishes, causing two minutes of errors. Making the application stage depend on the database stage fixes the order, and a backward-compatible migration keeps the old code working while it runs.
The bar lengths are illustrative.
True or false

Order in pipelines and templates

Exam skills 3.4.2

Check how pipelines and Resource Manager decide deployment order.

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

Verifying between steps

A finished deployment task does not prove that a service works: the process may have started and then failed. Each dependent stage should wait for evidence of health. Common approaches are a smoke test that calls a health endpoint with retries, a readiness check in Kubernetes, and a check such as Invoke REST API on the following environment.

- script: |
    for i in {1..20}; do
      status=$(curl -s -o /dev/null -w "%{http_code}" https://api.contoso.com/healthz)
      if [ "$status" = "200" ]; then exit 0; fi
      sleep 15
    done
    exit 1
  displayName: Wait for the API to report healthy

Reducing the need for strict order

Strict ordering creates fragile releases, and it couples teams. The better long-term approach is to make each component tolerant of neighbouring versions.

  • Backward-compatible changes mean that a new API still serves old clients, for example by adding fields instead of renaming them.
  • API versioning lets old and new contracts run together.
  • Expand and contract makes schema changes in compatible steps, as the database lesson explains.
  • Feature flags let code be deployed in any order, with the behaviour enabled when everything is ready.
  • Consumer-driven contract tests verify that a service still meets what its consumers expect.

If components can be deployed independently in any order, then each team can release on its own schedule, and that is a major goal of service-oriented design.

Match the pairs

Techniques that loosen ordering

Exam skills 3.4.2

Match each technique with how it lets components deploy in any order.

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

A race between stages

An application and its database migration deploy in parallel stages. Users occasionally see errors for two minutes after each release, because the new code runs before the migration finishes. What is the most complete fix?

The application stage should depend on the database stage, and the migration should be backward compatible so that the old application continues to work while it runs. Making the order explicit removes the race. A wait step would be unreliable, because migration time varies. Retrying failed user requests would hide the symptom, and would not correct the order.

Check yourself

Why is a successful deployment task not proof that a service works?

Show answer

The process may start and then fail. A smoke test or readiness check gives real evidence.

Exam Tips

Remember for the exam

  • A typical order is infrastructure, data, back-end services, front ends, then traffic.
  • Use dependsOn or needs instead of timing assumptions.
  • A finished task does not prove health; run a smoke test.
  • Backward compatibility and flags reduce ordering constraints.
  • Bicep infers dependencies from symbolic references.