Web Session Clustering: No Session Left Behind
Join the DZone community and get the full member experience.
Join For FreeClustering and failing-over web sessions is certainly not a new topic, but time proves that this topic never gets old either. No e-commerce site wants to loose any customers in case of a server crash. The old approach of sticky sessions does not seem to do the trick anymore, as it often causes uneven load distribution across cluster with certain servers being overloaded while others being almost idle.
Web session clustering provides freedom of load balancing user sessions to any app server without losing intermediate user session data. Why? Because underneath it takes advantage of in-memory distributed caching technology which ensures that user sessions are available in memory regardless of which server is hit. With this approach fault tolerance comes automatically - if a server crashes, simply go to another server and your session will still be available. All of this happens transparently to user who simply continues to browse and add items to the shopping cart as if nothing happened.
As an example, diagram below illustrates how web session clustering works in GridGain:
With GridGain In-Memory Database technology (IMDB) web sessions will be either replicated to all servers or partitioned across the cluster, where every cluster node will serve as a primary node for a particular web session. In case of partitioned strategy, it is possible to configure any number of backup copies within the cluster to ensure fault tolerance. All sessions will be eagerly removed from cache whenever they expire in the app server to free up memory space for others.
Configuration is as easy as adding a few lines into your web.xml file, like so:
Web session clustering provides freedom of load balancing user sessions to any app server without losing intermediate user session data. Why? Because underneath it takes advantage of in-memory distributed caching technology which ensures that user sessions are available in memory regardless of which server is hit. With this approach fault tolerance comes automatically - if a server crashes, simply go to another server and your session will still be available. All of this happens transparently to user who simply continues to browse and add items to the shopping cart as if nothing happened.
As an example, diagram below illustrates how web session clustering works in GridGain:
With GridGain In-Memory Database technology (IMDB) web sessions will be either replicated to all servers or partitioned across the cluster, where every cluster node will serve as a primary node for a particular web session. In case of partitioned strategy, it is possible to configure any number of backup copies within the cluster to ensure fault tolerance. All sessions will be eagerly removed from cache whenever they expire in the app server to free up memory space for others.
Configuration is as easy as adding a few lines into your web.xml file, like so:
... <!-- Declare listener for web sessions caching. --> <listener> <listener-class> org.gridgain.grid.cache.websession.GridWebSessionServletContextListener </listener-class> </listener> <!-- Specify GridGain configuration (relative to GRIDGAIN_HOME). --> <context-param> <param-name>GridGainConfigurationFilePath</param-name> <param-value>/examples/config/spring-cache.xml</param-value> </context-param> <!-- Specify the name of GridGain cache for web sessions. --> <context-param> <param-name>GridGainWebSessionsCacheName</param-name> <param-value>session-cache</param-value> </context-param> ...Once configured, simply bring up as many instances of your favorite app server and web sessions will be automatically clustered and cached in memory.
Session (web analytics)
clustering
Published at DZone with permission of Dmitriy Setrakyan, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
Trending
-
A Complete Guide to AWS File Handling and How It Is Revolutionizing Cloud Storage
-
Front-End: Cache Strategies You Should Know
-
Alpha Testing Tutorial: A Comprehensive Guide With Best Practices
-
A React Frontend With Go/Gin/Gorm Backend in One Project
Comments