0
0
Azurecloud~10 mins

Multi-region deployment patterns in Azure - Commands & Configuration

Choose your learning style9 modes available
Introduction
Deploying applications in multiple regions helps keep them running even if one region has problems. It also makes apps faster for users far away by placing copies closer to them.
When you want your app to stay online even if one data center fails.
When users are spread across different continents and need fast access.
When you want to meet legal rules that require data to stay in certain countries.
When you want to balance traffic so no single region gets overloaded.
When you want to reduce delays by serving users from the nearest location.
Config File - main.bicep
main.bicep
param location1 string = 'eastus'
param location2 string = 'westeurope'

resource appServicePlan1 'Microsoft.Web/serverfarms@2022-03-01' = {
  name: 'myAppServicePlanEastUS'
  location: location1
  sku: {
    name: 'P1v2'
    tier: 'PremiumV2'
  }
}

resource appServicePlan2 'Microsoft.Web/serverfarms@2022-03-01' = {
  name: 'myAppServicePlanWestEurope'
  location: location2
  sku: {
    name: 'P1v2'
    tier: 'PremiumV2'
  }
}

resource webApp1 'Microsoft.Web/sites@2022-03-01' = {
  name: 'myWebAppEastUS'
  location: location1
  properties: {
    serverFarmId: appServicePlan1.id
  }
}

resource webApp2 'Microsoft.Web/sites@2022-03-01' = {
  name: 'myWebAppWestEurope'
  location: location2
  properties: {
    serverFarmId: appServicePlan2.id
  }
}

resource trafficManager 'Microsoft.Network/trafficManagerProfiles@2021-02-01' = {
  name: 'myTrafficManagerProfile'
  location: 'global'
  properties: {
    trafficRoutingMethod: 'Performance'
    dnsConfig: {
      relativeName: 'myapptraffic'
      ttl: 30
    }
    monitorConfig: {
      protocol: 'HTTP'
      port: 80
      path: '/'
    }
    endpoints: [
      {
        name: 'endpointEastUS'
        type: 'Microsoft.Network/trafficManagerProfiles/azureEndpoints'
        properties: {
          targetResourceId: webApp1.id
          endpointStatus: 'Enabled'
          endpointLocation: location1
        }
      }
      {
        name: 'endpointWestEurope'
        type: 'Microsoft.Network/trafficManagerProfiles/azureEndpoints'
        properties: {
          targetResourceId: webApp2.id
          endpointStatus: 'Enabled'
          endpointLocation: location2
        }
      }
    ]
  }
}

This Bicep file creates two App Service plans and web apps in two different Azure regions: East US and West Europe.

It also creates a Traffic Manager profile that routes users to the closest web app based on performance.

The trafficRoutingMethod set to 'Performance' ensures users connect to the fastest endpoint.

The monitorConfig checks app health to avoid sending traffic to unhealthy apps.

Commands
This command deploys the Bicep template to create the multi-region web apps and Traffic Manager profile in the specified resource group.
Terminal
az deployment group create --resource-group myResourceGroup --template-file main.bicep
Expected OutputExpected
{ "id": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/myResourceGroup/providers/Microsoft.Resources/deployments/deploymentName", "name": "deploymentName", "properties": { "provisioningState": "Succeeded", "outputs": {} } }
--resource-group - Specifies the Azure resource group to deploy resources into
--template-file - Points to the Bicep file with the deployment configuration
This command checks the details of the web app deployed in East US to confirm it is created and running.
Terminal
az webapp show --name myWebAppEastUS --resource-group myResourceGroup
Expected OutputExpected
{ "id": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/myResourceGroup/providers/Microsoft.Web/sites/myWebAppEastUS", "location": "eastus", "name": "myWebAppEastUS", "state": "Running", "type": "Microsoft.Web/sites" }
--name - Specifies the name of the web app to show
--resource-group - Specifies the resource group where the web app exists
This command shows the Traffic Manager profile details to verify the multi-region routing setup.
Terminal
az network traffic-manager profile show --name myTrafficManagerProfile --resource-group myResourceGroup
Expected OutputExpected
{ "name": "myTrafficManagerProfile", "location": "global", "properties": { "trafficRoutingMethod": "Performance", "dnsConfig": { "relativeName": "myapptraffic", "ttl": 30 }, "endpoints": [ { "name": "endpointEastUS", "properties": { "endpointStatus": "Enabled", "endpointLocation": "eastus" } }, { "name": "endpointWestEurope", "properties": { "endpointStatus": "Enabled", "endpointLocation": "westeurope" } } ] } }
--name - Specifies the Traffic Manager profile name
--resource-group - Specifies the resource group where the profile exists
Key Concept

If you remember nothing else from this pattern, remember: use Traffic Manager to route users to the closest healthy app instance in different regions for better availability and speed.

Common Mistakes
Deploying apps in multiple regions but not setting up Traffic Manager or DNS routing.
Users will not be directed to the closest or healthy region, losing the benefits of multi-region deployment.
Always configure Traffic Manager or a similar routing service to manage user traffic across regions.
Not monitoring app health in Traffic Manager configuration.
Traffic Manager may send users to an app instance that is down, causing errors.
Set up health probes in Traffic Manager to check app status and avoid routing to unhealthy endpoints.
Using the same app name in different regions without unique names.
Azure requires unique names for web apps, so deployment will fail or overwrite.
Use unique names for each regional app instance.
Summary
Deploy web apps in multiple Azure regions using App Service plans.
Use Azure Traffic Manager with performance routing to direct users to the closest healthy app.
Verify deployments and routing setup with Azure CLI commands.