My web application is deployed on Azure App Service with multiple instances (scale out). It has a an API to generate a report. I want that a request to this API only go to a specific instance.
So I am thinking about writing a Javascript code to modify the value of ARR Affinity cookies before seding a request to the API so that the request go to the specify instance id.
I found an SO post in 2017 with an example code to set the cookies.
How to get access to azure app service instances directly
But I also found another SO post with someone stated that we should not interfere with this cookies value.
Azures Arr Affinity response cookie
I aslo asked ChatGPT and it told me it is valid to modify the cookies.
But all the resource URLs it gave me are expired and return 404.
Now I cannot find any Azure documentation that mentioned about the possiblity to modify this cookies manually.
So the question is can/should I write code in my application either front-end or back-end to modify the ARR Affinity cookies?
Changing ARRAffinity
cookie is not the most robust solution because Azure platform does not guarantee that app service instances and their IDs will always stay the same. It is possible that individual instances can be restarted and even replaced during platform upgrades or if Azure detects that an instance is not healthy. In this case your API requests can end up on any instance and it will be difficult to choose a new "reporting" instance automatically.
Here are some options that can help to achieve what you want without interfering with ARRAffinity
cookie:
If your reporting API is resource-intensive and you want to isolate it from the main web application, the best thing to do will be creating a separate app service plan and an app service in it. This app service will have its own domain name so you can send all reporting API requests to the dedicated app service.
If you want to use the same app service plan and share resources between the web application and reporting API, it is also possible to create an additional app service in the same app service plan. By default both app services will be scaled out to the same number of instances but you can use the feature called Per-App Scaling
, and change app service's numberOfWorkers
property to the desired instance count. For example, reporting API app service can be limited to one instance and the main application can be scaled to 3 instances. For more information, see Per-App Scaling documentation.