Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Web Session Clustering: No Session Left Behind

DZone's Guide to

Web Session Clustering: No Session Left Behind

Free Resource

Transform incident management with machine learning and analytics to help you maintain optimal performance and availability while keeping pace with the growing demands of digital business with this eBook, brought to you in partnership with BMC.

Clustering 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:
...
 
<!-- 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.

Evolve your approach to Application Performance Monitoring by adopting five best practices that are outlined and explored in this e-book, brought to you in partnership with BMC.

Topics:

Published at DZone with permission of Dmitriy Setrakyan, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}