Round Robin with Sticky Session. Is it possible? [Answered]RSS

4 replies

Last post Dec 04, 2018 08:54 PM by Dvijne

  • Round Robin with Sticky Session. Is it possible?

    Dec 03, 2018 08:44 PM|Dvijne|LINK

    Hi all,

    There is a .NET web application which must be load balanced. Most of the functions are stateless but there are a few which are stateful. The developers have implemented a Request Header which only exists in the request if the session is stateful, therefore it must use a sticky session based on this header's value. The rest of the requests could be distributed with Round Robin.

    I have two webservers which host the application and an ARR which is the load balancer. I'm looking for a way to tell the ARR that if the Sticky Header exist then use the Server Variable Hash algorithm (and set the HTTP_STICKY_HEADER variable to it) otherwise go ahead with Round Robin. It is working fine until the Sticky Header is provided in the request. But if the request doesn't contain this header than the ARR cannot use the Server Variable Hash algorithm and always goes to the same host. So my question is: Is it possible to configure ARR to use sticky session if a request header exists and use round robin if not?

    Thank you.

    Regards,

    Dvijne

  • Rovastar Rovastar

    5469 Posts

    MVP

    Moderator

    Re: Round Robin with Sticky Session. Is it possible?

    Dec 04, 2018 01:44 AM|Rovastar|LINK

    I have never tired to setup affinity with a HTTP variable I always use the cookies and as ARR assigns these I have never had your problem so unsure about the best way to solve it.

    However this is what I would do.

    I would created 2 farms instead of just 1 and with the same servers in each. Lets call these FARM1withHeader and FARM1withoutHeader

    FARM1withHeader rewrite rule: The first farms URL rewrite rule would be the same as yours is now but have an (additional) condition in there that is HTTP_STICKY_HEADER value exist then goto FARM1withHeader

    Then you have another rule that you place below the first one.

    FARM1withoutHeader rewrite rule: This is just a general round robin rule with the servers in.

    The logic is that if it contains the HTTP header it matches the conditions and goes to 1 farm and the next rule will therefore not have a header and round robin and goto the other farm. As both farms contain the same servers your traffic should sticky the correct/relevant ones.

    It is a little messier but should be simple enough to setup.

    Troubleshoot IIS in style
    https://www.leansentry.com/
  • Re: Round Robin with Sticky Session. Is it possible?

    Dec 04, 2018 06:59 AM|Dvijne|LINK

    Hi Rovastar!

    Thank you for this idea! I've configured it and tested the solution with postman and I confirm it's working fine.

    One more question if I may.

    Currently I'm verifying if the Sticky Header exists with this condition:

    <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
    <add input="{HTTP_STICKY_HEADER}" pattern="[0-9a-zA-Z]+" />
    </conditions>

    My intent here is to check if the Sticky Header has a value. Is it a good approach or is there a better way to do it? (Some other way which checks the existence of the variable.)

    Thanks again!

    Regards,

    Dvijne

  • Rovastar Rovastar

    5469 Posts

    MVP

    Moderator

    Re: Round Robin with Sticky Session. Is it possible?

    Dec 04, 2018 08:07 PM|Rovastar|LINK

    Just a . should work and will be simpler

    <add input="{HTTP_STICKY_HEADER}" pattern="." />

    Troubleshoot IIS in style
    https://www.leansentry.com/
  • Re: Round Robin with Sticky Session. Is it possible?

    Dec 04, 2018 08:54 PM|Dvijne|LINK

    Thank you!