How to deploy an Azure API Management service instance to multiple Azure regions

Azure API Management supports multi-region deployment, which enables API publishers to distribute a single Azure API management service across any number of desired Azure regions. This helps reduce request latency perceived by geographically distributed API consumers and also improves service availability if one region goes offline.

A new Azure API Management service initially contains only one unit in a single Azure region, the Primary Region. Additional regions can be easily added through the Azure portal. An API Management gateway server is deployed to each region and call traffic will be routed to the closest gateway. If a region goes offline, the traffic is automatically redirected to the next closest gateway.

Note

Azure API Management replicates only the API gateway component across regions. The service management component is hosted only in the Primary Region. In case of an outage in the Primary Region, applying configuration changes to an Azure API Management service instance is not possible - including settings or policies updates.

Availability

Important

This feature is available only in the Premium tier of API Management.

Deploy an API Management service instance to a new region

Note

If you have not yet created an API Management service instance, see Create an API Management service instance.

In the Azure portal, navigate to the Scale and pricing page for your API Management service instance.

Scale tab

To deploy to a new region, click on + Add region from the toolbar.

Add region

Select the location from the drop-down list and set the number of units for with the slider.

Specify units

Click Add to place your selection in the Locations table.

Repeat this process until you have all locations configured and click Save from the toolbar to start the deployment process.

Delete an API Management service instance from a location

In the Azure portal, navigate to the Scale and pricing page for your API Management service instance.

Scale tab

For the location you would like to remove, open the context menu using the ... button at the right end of the table. Select the Delete option.

Confirm the deletion and click Save to apply the changes.

Route API calls to regional backend services

Azure API Management features only one backend service URL. Even though there are Azure API Management instances in various regions, the API gateway will still forward requests to the same backend service, which is deployed in only one region. In this case, the performance gain will come only from responses cached within Azure API Management in a region specific to the request, but contacting the backend across the globe may still cause high latency.

To fully leverage geographical distribution of your system, you should have backend services deployed in the same regions as Azure API Management instances. Then, using policies and @(context.Deployment.Region) property, you can route the traffic to local instances of your backend.

  1. Navigate to your Azure API Management instance and click on APIs from the left menu.
  2. Select your desired API.
  3. Click Code editor from the arrow dropdown in the Inbound processing.

    API code editor

  4. Use the set-backend combined with conditional choose policies to construct a proper routing policy in the <inbound> </inbound> section of the file.

    For example, the below XML file would work for West US and East Asia regions:

    <policies>
        <inbound>
            <base />
            <choose>
                <when condition="@("West US".Equals(context.Deployment.Region, StringComparison.OrdinalIgnoreCase))">
                    <set-backend-service base-url="http://contoso-us.com/" />
                </when>
                <when condition="@("East Asia".Equals(context.Deployment.Region, StringComparison.OrdinalIgnoreCase))">
                    <set-backend-service base-url="http://contoso-asia.com/" />
                </when>
                <otherwise>
                    <set-backend-service base-url="http://contoso-other.com/" />
                </otherwise>
            </choose>
        </inbound>
        <backend>
            <base />
        </backend>
        <outbound>
            <base />
        </outbound>
        <on-error>
            <base />
        </on-error>
    </policies>