Azure Tutorials

Traffic Manager and DNS-based Load Balancing in Azure

This tutorial guides you through setting up Azure Traffic Manager to provide DNS-based traffic load balancing for your Azure applications. Traffic Manager allows you to distribute traffic to different endpoints in various geographic regions, improving application availability and responsiveness.

Prerequisites

Steps to Configure Traffic Manager

1

Create a Traffic Manager Profile

Navigate to the Azure portal. Search for "Traffic Manager profiles" and click "Create".

  1. Select your Subscription and Resource group.
  2. Give your profile a unique Name. This name will be part of the DNS name for your Traffic Manager endpoint (e.g., my-app.trafficmanager.net).
  3. Choose a Routing method. For this tutorial, we'll use Priority routing, which allows you to designate a primary endpoint and failover endpoints. Other options include Weighted, Performance, Geographic, and Multivalue.
  4. Select the Resource group and Location for the profile.
  5. Click "Review + create", then "Create".
2

Add Endpoints to the Profile

Once your Traffic Manager profile is created, go to its resource blade. Under Settings, select Endpoints.

  1. Click "Add".
  2. Choose the Type of endpoint (e.g., "Azure endpoint" for an App Service or Virtual Machine).
  3. Select the Target resource (your deployed Azure service).
  4. Assign a Priority number. Lower numbers indicate higher priority. For Priority routing, the endpoint with the lowest priority number is considered the primary.
  5. Repeat this process for all your application's endpoints, assigning increasing priority numbers (e.g., 1 for the primary, 2 for the first failover, 3 for the second failover).
  6. Configure Health probes. These probes are crucial for Traffic Manager to detect if an endpoint is unhealthy and needs to be bypassed. Configure the protocol (HTTP, HTTPS, TCP), port, and path for the probe to check.
Important: Ensure your health probe path is configured to a valid and accessible resource within your application that reliably indicates service health.
3

Configure DNS TTL

Under Settings, select Configuration. The Time-to-Live (TTL) setting determines how long DNS resolvers cache the Traffic Manager's response. A lower TTL means changes to endpoint health or routing will propagate faster but can increase DNS query load.

Adjust the TTL as needed for your application's requirements.

4

Test Your Traffic Manager Configuration

After adding endpoints and configuring the profile, it will take a few minutes for the changes to propagate globally. To test:

  1. From a machine outside your Azure network, open a command prompt or terminal.
  2. Use a DNS lookup tool like nslookup or dig to query your Traffic Manager profile's DNS name (e.g., nslookup my-app.trafficmanager.net).
  3. You should receive an IP address that corresponds to your primary, healthy endpoint.
  4. To simulate a failover, you can temporarily disable your primary endpoint or make it unreachable. Then, repeat the DNS lookup. Traffic Manager should return the IP address of the next available healthy endpoint based on your routing method.

Understanding DNS-based Load Balancing

Azure Traffic Manager operates at the DNS layer. When a user requests your application's domain name (e.g., www.your-app.com), the DNS query is directed to Traffic Manager. Traffic Manager then uses its configured routing method and endpoint health status to return the IP address of the most appropriate endpoint to the user's DNS resolver. The user's browser then connects directly to that IP address.

Key Benefits

By leveraging Traffic Manager, you can build more robust and responsive applications on Azure.