Tuesday, September 20, 2011

.Net Sessions in Load Balanced WebFarms


Introduction
This document is aimed to write some fact about session issue in Clustering scenario.  Web cluster is mostly implemented using web-farms. The following facts are based on the project based experiences which author has gained.
1. Session Issue
Session can not be managed in a web farm implementation because the load balancer can route the traffic from the same requester to another web server based on several criteria. Few criteria are web/app server's current load, amount of memory remaining, etc.
The moment second or subsequent web page request is routed to another web server by the load balance server (e.x - F5) , your site will stop working and your data may be lost.
Find below some facts
1. In Web Farm, there are at least following servers.
Once load balancer
Two or more Web Servers
Once or more App Servers
One or more database servers
2. By default, in a load-balanced web farm implementation, it is not guaranteed that request from the same client will always be severed by the same web server from the Farm. It happens due the fact that the request can be routed to any available web server by the load balancer. F5 is an example of good load balance server. This is heavenly used by clients who has very sensitive type of data, like Banking Clients.
3. In this case, the server sessions which were created and stored on web server will not be available to another web server, if the same user requests/submits a web page and he will get error.
4. So in web farm implementation,  server-based session concepts can not be used without any special arrangements.
5. Though in several organization, for web farm implementation, the default configuration of load balancer is such a ways that the load balance always sent the client request to the same web server for first 300 seconds from the time of first request. Several Banking clients keeps this setting as it is. Note that is a very important concept to remember. It can solve a lot of issues after your first time deployment of any code in production.

Relevant AD
This ad may be helpful, if relevant to your search.


Alternatives:  .Net web in LoadBalanced scenario in Web-farm Implementation
Option  A :    Session State alternatives (changes at code level)
1.     Use Cookies to preserve data between different calls.
a.       Cookies are more scalable option than using sessions. Since all data are stored on client machine, memory on server remains free for other tasks. Instead of spending server resources like memory or database, ASP.NET will distribute data to visitors' computers.
2.       ASP.NET ViewState
a.     ASP.NET ViewState state stores information in page's HTML code, as hidden field named __VIEWSTATE. ViewState is also very scalable solution. Like in case when using cookies, information are stored on client side and don't load on server.
b.    Unlike Session state, ViewState is designed to preserve data between post backs on same page. You can't, at least by default, send data between pages using ViewState. There are some workarounds, you can, for example place some data to ViewState and then use Server.Transfer to load the second page. In this case, ViewState variables will be visible on second page so you practically transferred data between different pages using ViewState
3.       Use hidden fields
a.     You can place standard HiddenField control on web form and use its Value property to store user's data
4.       Query strings
a.     Query strings were common option to send data between pages. Even ASP.NET session state uses query string variable in URL if Cookieless parameter is set to true. So, query strings work if user is disabled cookies in browser.
b.      Disadvantage of query strings is that you can't transfer a lot of data on this way. I think your application uses session to temporarily store preventative data type and hence Query string is suitable option for you.
5.       Profile properties
a.  Profile data remains after visitor leaves website and session expires. Because data are stored in Sql Server database by default, they are not affected on ASP.NET restart or even IIS restart.
Note: If your application needs to persist some sensitive date across multiple page loads, even session variables are not all a secure mechanism to store these data because several viral or trojan attack can read this session data from server’s memory. The most reliable way to keep user's information across sessions is to store them to database on server. You can do it manually, but it is usually more efficient to use Profile properties.

Option  B :    Change at Infrastructure level
1.       New SQL Session state sever
2.       New ASP.Net Out Proc Server
For both of the above, the network/server engineer must have one more/shared computer hardware which will serve as common location to store sessions of each web server present in the web farm. I think we don’t have this kind of infrastructure setup either in QA or Production environment as of now. If needed , it will take a lot of time and money and of course several level of approvals.
Conclusion : I have generally seen (where sticky session is not enable on load balancer) that Option A.2, A.3 and A.4 are used simultaneously across the whole application starting right from coding.
Did you like this post ? Do leave a comment or share with your Facebook friends. This will give me more reasons to write such posts.

24 comments:

  1. michael kors outlet, http://www.michaelkorsoutlets.uk/
    ralph lauren shirts, http://www.poloralphlaurenshirts.us.com/
    football shirts, http://www.cheapfootballshirt.org.uk/
    ray ban sunglasses, http://www.raybansunglassesonline.in.net/
    tiffany outlet, http://www.tiffany-outlet.us.com/
    calvin klein underwear, http://www.calvinklein.in.net/
    tory burch outlet, http://www.toryburch.in.net/
    michael kors factory outlet, http://www.michaelkorsfactoryoutlet.us.org/
    air jordan 4, http://www.airjordan4.org/
    true religion jeans, http://www.truereligionjeansoutlet.com/
    tiffany and co jewelry, http://www.tiffanyandco.in.net/
    nike huarache, http://www.nike-airhuarache.co.uk/
    oakley outlet, http://www.oakleyoutlet.in.net/
    kobe 9, http://www.kobe9elite.us.com/
    vans shoes, http://www.vans-shoes.cc/
    cheap michael kors handbags, http://www.cheapmichaelkorshandbag.in.net/
    nike outlet store, http://www.nikeoutletstore.us/
    cheap jordans, http://www.cheapjordans.us.org/
    air max 2014, http://www.airmax2014.net/
    michael kors wallet, http://www.michaelkorswallet.net/
    hermes bags, http://www.hermesbags.co.uk/
    herve leger, http://www.herveleger.us.com/
    coach outlet, http://www.coachoutletstoreonline.in.net/
    christian louboutin, http://www.scarpelouboutin.it/
    karen millen dresses, http://www.karenmillendressesoutlets.co.uk/
    jordan shoes, http://www.jordanshoes.us.com/
    ray ban, http://www.occhiali-rayban.it/
    0929maoqiuyun

    ReplyDelete
  2. steelers jerseys, http://www.pittsburghsteelersjersey.com/
    michael kors handbags, http://www.michaelkorsusa.us/
    cheap ugg boots, http://www.uggaustralia.in.net/
    kobe bryants shoes, http://www.kobeshoes.us/
    louis vuitton handbags outlet, http://www.louisvuittonhandbag.us/
    true religion outlet, http://www.truereligionjeansoutlet.com/
    cheap nba jerseys, http://www.nbajerseys.us.com/
    san antonio spurs, http://www.sanantoniospursjersey.com/
    tiffany and co, http://www.tiffanyandco.in.net/
    wellensteyn outlet, http://www.barbour.us.com/
    adidas outlet, http://www.adidasoutletstore.us.com/
    canada goose outlet, http://www.canadagooseoutlet.com.co/
    michael kors outlet, http://www.michaelkorsoutlet-store.us.com/
    bottega veneta outlet, http://www.bottegaveneta-outlet.net/
    canada goose outelt, http://www.uggbootscheap.eu.com/
    hollister shirts, http://www.hollistershirts.co.uk/
    tiffany and co, http://www.tiffany-outlet.us.com/
    swarovski outlet, http://www.swarovski-outlet.co.uk/
    basketball shoes,basketball sneakers,lebron james shoes,sports shoes,kobe bryant shoes,kobe sneakers,nike basketball shoes,running shoes,mens sport shoes,nike shoes
    winter jackets, http://www.cybermonday2015.us.com/
    mm1017

    ReplyDelete
  3. Coach Outlet http://www.coachoutletfactory-stores.us.com

    North Face Outlet http://www.northface-outlets.com.co

    Kate Spade Outlet http://www.katespadefactoryoutlet.in.net

    ED Hardy Outlet http://www.edhardypopsale.com

    Coach Outlet Store Online http://www.coachstoreonline.in.net

    Kate Spade Outlet http://www.katespadeoutletstore.in.net

    Cheap Jordans http://www.cheapjordansretro.us.com

    Michael Kors Outlet Store http://www.michaelkorsoutletsstores.us.com

    Coach Purses http://www.coachpurses.eu.com

    Coach Outlet http://www.coachoutlet2016.us.com

    Tory Burch Shoes http://www.toryburch-outlet.us.org

    Longchamp Outlet http://www.longchampoutlet.in.net

    Michael Kors Handbags http://www.innnov8.com

    Coach Outlet http://www.innnovate.com

    Red Bottom Shoes http://www.redbottomshoes.us.org

    Moncler Jackets http://www.monclerdownjackets.us.com

    North Face Outlet http://www.northfacestoreoutlet.in.net

    Kate Spade Outlet http://www.katespadeoutletstore.us.com

    Moncler Outlet http://www.moncleroutletonline.in.net

    Coach Factory http://www.maganates.com

    Coach Factory Outlet http://www.coachfactorysoutlet.in.net

    Kate Spade Outlet http://www.katesapdeoutlet.us.org

    Ray Ban Outlet http://www.raybanoutletstore.in.net

    Christian Louboutin Shoes http://www.christianlouboutinshoes2016.in.net

    North Face Outlet http://www.northfaceoutlets.us.org

    Coach Factory Outlet http://www.coachoutletstore.name

    Kate Spade Outlet http://www.katespadeoutletonline.name

    Coach Outlet http://www.coach-outlets.us.org

    Nike Roshe Run http://www.tanie-nikerosherun.pl

    Buty Nike Air Max http://www.airmaxsprzedazdla.pl

    Nike Air Max http://www.nikeairmax.us.org

    Red Bottom Shoes http://www.redbottomshoe.in.net

    Christian Louboutin Outlet http://www.christianlouboutinoutlet.us.org

    Balenciaga Handbags http://www.balenciagaoutlets.us.com

    Balenciaga Handbags http://www.balenciaga-handbags.us.com

    Kate Spade Outlet http://www.katespadefactoryoutlet.in.net

    Toms Shoes http://www.tomshoesoutlet.us.com

    Hermes Belt http://www.hermes-belts.us.com

    Prada Outlet http://www.pradafactoryoutlet.com

    Louis Vuitton Outlet http://www.louisvuittonsoutlet.us.com

    North Face Outlet Store http://www.northfaceoutletstore.in.net

    North Face Jackets http://www.north-face.in.net

    North Face http://www.north-faceoutlets.us.com

    Louis Vuitton Outlet http://www.louisvuitton-outlets.us.org

    Timberland Boots http://www.timberland-outlets.us.com

    Cheap Timberland Boots http://www.timberlandoutlet.us.com

    Tory Burch Outlet http://www.outlettoryburch.us.com

    Michael Kors Outlet http://www.michaelkorsoutletusa.us.com

    Ralph Lauren Outlet http://www.ralphlaurenstoreoutlet.us.com

    Gucci Shoes http://www.guccifactoryoutlet.name

    Gucci Outlet http://www.guccioutletco.us.com

    North Face Jackets http://www.northfacefactoryoutlet.us.com

    Prada Outlet http://www.pradaoutlets.in.net

    Hollister Clothing http://www.hollister-clothing.us.com

    Ferragamo Shoes http://www.ferragamoshoes.us.org

    Tiffany Outlet http://www.tiffany-outlets.us.com

    Tiffany Outlet http://www.tiffanyco-outlet.us.com

    NFL Jerseys http://www.nfljerseys.name

    Toms Outlet http://www.outlettoms.us.com

    Cheap Jordans http://www.cheapjordans.eu.com

    North Face Outlet http://www.thenorthfaceoutlet.us.org

    Michael Kors Outlet http://www.michael-korsoutletstores.us.com

    Prada Handbags http://www.pradaoutlet.us.org

    Chan Luu Sale http://www.chanluu.us.com

    Toms Outlet http://www.tomsoutletstores.us.com

    Kate Spade Outlet http://www.katespadeoutletonline.us.org

    Beats By Dr Dre http://www.beatsbydrdre.us.org

    Coach Outlet http://www.coachstoreoutlet.us.org

    Christian Louboutin Shoes http://www.christianlouboutinshoe.eu.com

    Valentino Shoes http://www.valentinoshoes.eu.com

    Michael Kors Outlet http://www.michaelkorsoutlet.us.org

    Coach Factory Outlet http://www.coachfactoryoutlet.us.org

    Coach Outlet Online http://www.coachoutletonlinestore.us.org

    Coach Purses http://www.coachpurse.us.com

    ReplyDelete
  4. This blog is so nice to me. I will continue to come here again and again. Visit my link as well. Good luck
    http://www.jualobataborsiherbal.com/ obat aborsi
    http://caramenggugurkankandungan.info/ cara menggugurkan kandungan
    http://obataborsi59.com/ obat aborsi
    http://obataborsi59.com/cara-menggugurkan-kandungan-dengan-cepat-dan-aman/ cara menggugurkan kandungan
    http://obattelatdatangbulan.info/ obat telat datang bulan
    http://klinikobataborsi.com/ jual obat aborsi
    http://jualobatpenggugurkandungan.net/ obat penggugur kandungan
    http://tandatandakehamilan.net/ tanda tanda kehamilan
    http://tandatandakehamilan.net/cara-cepat-dan-selamat-menggugurkan-kandungan/ cara menggugurkan kandungan

    ReplyDelete