Search code examples
azureazure-api-managementazure-front-door

balance 2 API endpoints proportionally with Azure FrontDoor


I am trying to balance 2 API Endpoints, on the same API management, to achieve a canary release trought FrontDoor. The first endpoint (let's say www.contoso.com/api1) stands for old application release and the second (www.contoso.com/api2) for the new one. In that way, i am planing to create a backend pool in frontdoor to balance proportionally 90% of request to the first endpoint and 10% to the second one.

I know know that the best way to do this is with 2 API Management services (like balancing to servers with different deployments), but is it posible just with one?

Thaks in advance


Solution

  • Use combination of choose and set-backend-service policies:

    <choose>
      <when condition="@(new Random().Next(10) < 9)">
        <set-backend-service baseUrl="https://www.contoso.com/api1" />
      </when>
      <otherwise>
        <set-backend-service baseUrl="https://www.contoso.com/api2" />
      </otherwise>
    </choose>