Azure GeoDistributed WebApps
Just Imagine you have a WebApp which addresses different people in different regions across the globe. Wouldn’t it be a good idea to spawn multiple instance and redirect requests to the closest occurrence?
A great way to do this is Azure Traffic Manager.
In my example, I’ll create two WebApps sitting on two different ServicePlans. Each pair in its own region. I put in the same RessourceGroup (just to ease cleanup after I’m done).
Afterward I’ll create a Traffic Manager Profile to LoadBalance between both WebApps, based on Geographic location.
Provisioning RessourceGroup, Service Plan and WebApps:
# Create RessourceGroup New-AzureRmResourceGroup -Name RG-Geo -Location "West US" # Create AppServicePlan in West US New-AzureRmAppServicePlan -Name SP-WestUS -Location "West US" -ResourceGroupName RG-Geo -Tier Standard -WorkerSize small -NumberofWorkers 1 # Create AppServicePlan in North Europe New-AzureRmAppServicePlan -Name SP-NorthEurope -Location "North Europe" -ResourceGroupName RG-Geo -Tier Standard -WorkerSize small -NumberofWorkers 1 #Create WebApp in WestUS New-AzureRmWebApp -Name WA-WestUS -AppServicePlan SP-WestUS -ResourceGroupName RG-Geo -Location "West US" #Create WebApp in North Europe New-AzureRmWebApp -Name WA-NorthEurope -AppServicePlan SP-NorthEurope -ResourceGroupName RG-Geo -Location "North Europe"
I’ve also uploaded a simple index.html which shows, on which location we are. Following the example for WestUS:
<html> <head> <title>Testing TrafficManager</title> </head> <body> <h1>Welcome to WestUs</h1> </body> </html>
Testing both WebApps.
Next, I am going to configure the Traffic Manager Profile. If you have trouble to find the Traffic Manager, its located under Network Section. Or simply use one of the multiple search bars.
Key here is the Routing Method. You can choose between the following:
Priority
Basically a Active Standby configuration. You have One primary WebApp and one or more backup WebApps.
Weighted
Similar to Round-Robin principle, except you can tune endpoints to be used more often than others.
Performance
Request gets routed to the closest WebApp. This is not necessarily the one with the shortest distance, but the one with the lowest network latency.
Geographic
Similar to performance. The main difference between Performance and Geographic is, Performance is using Recursive DNS Service location to determine where to route and Geographic is using source IP of the actual DNS query.
Also note, that the name you are giving to the Traffic Manager is going to be the part of the URL, which is available on later.
Last Step is to add the Endpoints.
Navigate to your Traffic-Manager –> Endpoint –> Add
Give your endpoint a Meaningfull name and choose App Service as Target Ressource type. Next you can select your WebApp as Target Ressource.
Lastly, you need to specify a Region. All requests coming from that region will be routed to the WebApp you chose earlier.
Thats basically it – now we can check if it works. To test it, I connected to VPN servers in each region and visited my Traffic-Managers URL.
Keep in mind, that in production environment you might want to have the content of both WebApps the same. So it might be usefull to use one of the Deployment Options like GitHub or similar.