Over a million developers have joined DZone.

Web Session Clustering: No Session Left Behind

DZone 's Guide to

Web Session Clustering: No Session Left Behind

· Performance Zone ·
Free Resource
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. -->
<!-- Specify GridGain configuration (relative to GRIDGAIN_HOME). -->
<!-- Specify the name of GridGain cache for web sessions. -->
Once configured, simply bring up as many instances of your favorite app server and web sessions will be automatically clustered and cached in memory.

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}