.netazureazure-web-app-servicesession-affinity

Can I modify the value of ARR Affinition cookies programmatically


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.

enter image description here

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?


Solution

  • 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: