I’m trying to figure out how to distribute traffic between two backend services using Azure API Management policies. Specifically, I need to route requests between two Logic Apps deployed in separate regions.
I’ve been looking at the policy documentation and noticed there are some control flow options available, but I’m struggling to understand how to:
- Check if the primary backend service is responding
- Automatically redirect traffic to the secondary service when the primary one fails
Currently my backend configuration is pretty basic:
<backend-service>
<send-request/>
</backend-service>
What’s the best approach to implement this kind of failover mechanism? Are there specific policy elements I should be using to monitor backend health and switch between services?
Use a circuit breaker pattern with the <send-request>
policy and error handling. I dealt with something similar when setting up failover between regional endpoints. Wrap your backend calls in a <try-catch>
block - put your primary Logic App endpoint in the try section with proper timeout values. In the catch section, handle specific error codes and automatically route to your secondary region. Add a <cache-lookup>
policy to store backend health status temporarily so you don’t waste time retrying during known outages. The trick is setting the right timeout thresholds and deciding which HTTP status codes should trigger failover vs. actual request failures.
Interesting setup! You could try combining <retry>
policy with <choose>
conditions. Are you thinking policy level or would Azure Traffic Manager be better here? What response times are you getting between regions?
yea, <forward-request>
with multiple backends is definitely the move. throw it in a <choose>
block - hit the primary service first, and if it fails, flip to backup. cache those responses for a few minutes while ur at it!