locked
Considerations we need to have when deploying application with multiple instances of Web Role into azure RRS feed

  • Question

  • Hi,

    If we deploy a site into azure with WebRole instance count greater that 1, is session state, Application State is shared among the Instances automaticaly? If not what is the solution?

    Consider we have created two instances for webRole. If I made a request to the server, consider Instance1 processed the request given the response. In this request processing we saved some data into session. When I do a post back consider due to some reason Instance2 processed my postback request. Here my question is how the Instance2 can access the session data that is saved  in my previous request?

    Thanks



    • Edited by Ashok Dasari Thursday, September 15, 2011 12:15 PM
    Thursday, September 15, 2011 10:42 AM

Answers

  • Ashok,

    Anytime you build an app that can span multiple nodes or instances, you have to deal with making sure your nodes are stateless. Windows Azure is no different. Windows Azure doesn't support session affinity, which is a good thing when you want to build highly-available, massively scalable apps.

    You must maintain state outside of the instance. As Kunal mentioned, one of your options would be to store your session state in AppFabric Caching. But you don't have to use AppFabric Caching. You could store your session state in Azure Table Storage or even SQL Azure.

    The Patterns & Practices team at Microsoft created some great guidance for what you need to do when moving a web app to Windows Azure. It is titled, "Moving Applications to the Cloud" and you can get it at http://msdn.microsoft.com/en-us/library/ff728592.aspx. This guidance includes a book that walks through the migration, includes all the code, and even hands-on labs. In this book, they walk through handling session state. I highly recommend this guidance and the other cloud and Windows Phone guidance from Patterns and Practices.

    Eric


    Eric D. Boyd - Director, Chicago + Cloud at Centare 
    Blog | twitter
    Thursday, September 15, 2011 6:46 PM
  • Hi Ashok,

    If your session state is stored in instance 1 machine and subsequent request gets served by instance 2 then session state won't be accessed from instance 2 machine.

    To share the session state and application state across all azure web role instances, you will need to use Azure Appfabric Caching.

    Kindly refer to this link - http://msdn.microsoft.com/en-us/gg457897

    Hope this helps.

    Regards,

    Kunal


    Mark As Answer if it helps you | My Blog
    Thursday, September 15, 2011 12:16 PM

All replies

  • Hi Ashok,

    If your session state is stored in instance 1 machine and subsequent request gets served by instance 2 then session state won't be accessed from instance 2 machine.

    To share the session state and application state across all azure web role instances, you will need to use Azure Appfabric Caching.

    Kindly refer to this link - http://msdn.microsoft.com/en-us/gg457897

    Hope this helps.

    Regards,

    Kunal


    Mark As Answer if it helps you | My Blog
    Thursday, September 15, 2011 12:16 PM
  • Ashok,

    Anytime you build an app that can span multiple nodes or instances, you have to deal with making sure your nodes are stateless. Windows Azure is no different. Windows Azure doesn't support session affinity, which is a good thing when you want to build highly-available, massively scalable apps.

    You must maintain state outside of the instance. As Kunal mentioned, one of your options would be to store your session state in AppFabric Caching. But you don't have to use AppFabric Caching. You could store your session state in Azure Table Storage or even SQL Azure.

    The Patterns & Practices team at Microsoft created some great guidance for what you need to do when moving a web app to Windows Azure. It is titled, "Moving Applications to the Cloud" and you can get it at http://msdn.microsoft.com/en-us/library/ff728592.aspx. This guidance includes a book that walks through the migration, includes all the code, and even hands-on labs. In this book, they walk through handling session state. I highly recommend this guidance and the other cloud and Windows Phone guidance from Patterns and Practices.

    Eric


    Eric D. Boyd - Director, Chicago + Cloud at Centare 
    Blog | twitter
    Thursday, September 15, 2011 6:46 PM
  • Good answer, Eric.

    Just want to provide an additional link to the Developing Application for the Cloud guide, in which we discuss various options for handling state in web apps.

    Both guides ("Moving..." and "Developing...") have been updated and available in their 2nd editions now.

    Tuesday, June 26, 2012 1:11 AM