Use Cases

Web Session Clustering

Maintain a consistent customer experience and eliminate delays and downtime through Hazelcast web session clustering.

Web Session Clustering

Web and application servers can scale out to handle huge loads with devices such as load balancers, which also provide redundancy. However, this setup introduces a new problem for applications that use web sessions: if a server fails and the load balancer redirects the user to a new server, the session data is lost since sessions are tied to specific application servers. The solution to this problem is to provide web session clustering (or “web session replication”) which allows any application server to access the system-wide pool of stored session data.

Open source application servers typically provide a way to plug in a web session clustering solution but do not provide the clustering mechanism itself. Commercial application servers may provide a clustering mechanism, but these are typically neither robust nor performant.

Hazelcast for Web Session Clustering

Hazelcast maintains user sessions in its cluster in memory, creating multiple copies for reliability. Every application server is set up to access Hazelcast so that all have access to all user sessions. Sessions are evenly distributed across the Hazelcast cluster. In the event of an application server failure, the load balancer redirects the session to another application server. You can even shut down individual application servers for maintenance without losing session data. The handoff to the new application server is seamless for the user for the highest level of customer experience.

Hazelcast for Web Session Clustering

Hazelcast for Web Session Clustering

The Hazelcast Advantage

High Performance and Scale with No Application Modification Required

Hazelcast processes all data in memory, so it delivers extremely fast performance for web session clustering for the best possible user experience. Hazelcast scales horizontally, so as your online business grows, it’s easy and cost-effective to expand your capacity by simply adding more hardware servers to your cluster.

Hazelcast provides web session clustering with native integration for Tomcat and Jetty application servers. Hazelcast can also be integrated with generic application servers through the use of filters. Hazelcast is delivered as a compact JAR file that is installed directly on the server, so it doesn’t require any modifications to your applications.

Tomcat Web Session Replication

Apache Tomcat is an open-source web server and servlet container developed by the Apache Software Foundation (ASF). Tomcat implements several Java Enterprise Edition specifications including Java Servlet, JavaServer Pages (JSP), Java EL, and WebSocket, and provides a “pure Java” HTTP web server environment for Java code to run in.

Hazelcast IMDG and Tomcat

You can use Tomcat Web Session Replication with Hazelcast IMDG version 3.0 or higher. Tomcat Web Session Replication with Hazelcast IMDG is a container-specific module that enables you to perform session replication for JEE web applications without making changes to your applications. Tomcat Web Session Replication in Hazelcast IMDG is a Hazelcast module where the state of each created HttpSessionObject is kept in a Hazelcast distributed map.

Requirements

The following are required to enable Hazelcast Session Clustering with Tomcat.

  • Tomcat 6, 7, 8 and 8.5 are supported
  • The target application or web server should support Java 1.6+
  • The target application or web server should support Servlet 3.0+ spec
  • The session objects that need to be clustered have to be serializable
Easy to set up

An advantage of the Tomcat Web Session Replication Module for Hazelcast IMDG is that you don’t change anything in your application. You only need to perform some configuration in your Tomcat container to easily attach Hazelcast session replication to your web applications.

To configure Tomcat for Hazelcast IMDG:

Put hazelcast-all-.jar, hazelcast-tomcat-sessionmanager-.jar and hazelcast.xml (if you want to change defaults) in the folder $CATALINA_HOME/lib/..
Put a element into the file $CATALINA_HOME$/conf/server.xml as shown below.

<Server>
...
<Listener className="com.hazelcast.session.P2PLifecycleListener"/>
...
</Server>

Put a <manager> element into the file $CATALINA_HOME$/conf/context.xml as shown below.

<context>
...
<manager classname="com.hazelcast.session.HazelcastSessionManager"/>
...
</context>

Jetty Web Session Replication

Hazelcast Jetty Web Session Replication Architecture
Hazelcast Jetty Web Session Replication Architecture.

Jetty is a pure Java-based HTTP (Web) server and Java Servlet container. Jetty is developed as a free and open source project as part of the Eclipse Foundation. Jetty supports the latest Java Servlet API (with JSP support) as well as protocols SPDY and WebSocket.

Hazelcast IMDG and Jetty

You can use Jetty Web Session Replication with Hazelcast IMDG version 3.0 or higher. Jetty Web Session Replication with Hazelcast IMDG is a container-specific module that enables you to perform session replication for JEE web applications without making changes to your applications. Jetty Web Session Replication in Hazelcast IMDG is a Hazelcast module where the state of each created HttpSessionObject is kept in a Hazelcast distributed map.

Requirements

The following are required for enabling Hazelcast Session Clustering with Jetty.

  • Jetty 7, 8, and 9 are supported
  • The target application or web server should support Java 1.6+
  • The target application or web server should support Servlet 3.0+ spec
  • The session objects that need to be clustered have to be serializable

Easy to Set Up

An advantage of the Jetty Web Session Replication Module for Hazelcast IMDG is that you don’t change anything in your application. You only need to perform some configuration in your Jetty container to easily attach Hazelcast web session replication to your web applications.

To configure Jetty for Hazelcast IMDG:

Put hazelcast.xml in the folder $JETTY_HOME/etc
Put hazelcast-all-.jar, and hazelcast-jetty-sessionmanager-.jar and hazelcast.xml (if you want to change defaults) in the folder $JETTY_HOME/lib/ext.

Configuring the HazelcastSessionIdManager:

<Set name="sessionIdManager">
   <New id="hazelcastIdMgr" class="com.hazelcast.session.HazelcastSessionIdManager">
       <Arg><Ref id="Server"/></Arg>
       <Set name="configLocation">etc/hazelcast.xml</Set>
   </New>
</Set>

Configuring the HazelcastSessionManager:

<Ref name="Server" id="Server">
   <Call id="hazelcastIdMgr" name="getSessionIdManager"/>
</Ref>
<Set name="sessionHandler">
   <New class="org.eclipse.jetty.server.session.SessionHandler">
       <Arg>
           <New id="hazelcastMgr" class="com.hazelcast.session.HazelcastSessionManager">
               <Set name="idManager">
                   <Ref id="hazelcastIdMgr"/>
               </Set>
           </New>
       </Arg>
   </New>
</Set>

Generic Web Session Replication

With Hazelcast Open Source Generic Web Session Replication, you can easily store your user sessions in Hazelcast using any application server that supports filters.

If you are running on Tomcat or Jetty, consider using the native web session replication modules for these application servers. Native modules are more development-operations friendly and better integrated into Tomcat and Jetty for better performance.

Requirements

The following are required for enabling Hazelcast Web Session Clustering.

  • The target application or web server should support Java 1.5+.
  • The target application or web server should support Servlet 2.4+ spec.
  • The session objects that need to be clustered have to be serializable.

Easy to Set Up

You don’t change anything in your application. You only need to perform some configuration to easily attach Hazelcast Web Session Replication to your web applications.

Put the hazelcast and hazelcast-wm jars in your WEB-INF/lib directory.

Optionally, if you wish to connect to a cluster as a client, add hazelcast-client as well.

Put the following XML into the web.xml file. Make sure the Hazelcast filter is placed before all the other filters if there are any: for example, you can put it at the top.

<filter>
<filter-name>hazelcast-filter</filter-name>
<filter-class>com.hazelcast.web.WebFilter</filter-class>
<!– Name of the distributed map storing your web session objects –>
<init-param>
<param-name>map-name</param-name>
<param-value>my-sessions</param-value>
</init-param>
<!– How is your load-balancer configured? stick-session means all requests of a session is routed to the node where the session is first created. This is excellent for performance. If sticky-session is set to false, when a session is updated on a node, entry for this session on all other nodes is invalidated. You have to know how your load-balancer is configured before setting this parameter. Default is true. –>
<init-param>
<param-name>sticky-session</param-name>
<param-value>true</param-value>
</init-param>
<!– Are you debugging? Default is false. –>
<init-param>
<param-name>debug</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>hazelcast-filter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>FORWARD</dispatcher>
<dispatcher>INCLUDE</dispatcher>
<dispatcher>REQUEST</dispatcher>
</filter-mapping>
<listener>
<listener-class>com.hazelcast.web.SessionListener</listener-class>
</listener>

Hazelcast Web Session Clustering Features

High Performance and No Application Alteration

As an in-memory solution, performance of web session clustering and replication is very high, and needs no alterations to your application tier. Perform web session clustering without modifying existing applications.

Easy to Scale Out

As your online business grows and customers increasingly use your website, Hazelcast can keep up with the load by adding new Hazelcast members to extend your cluster capacity.

Fast Session Access

Hazelcast IMDG is an in-memory data grid, so all data operations are handled in-memory. This gives users of your online business a significantly faster (and better!) user experience.

Offload Web Sessions to Existing Cluster

Configure Web Session Replication to use an existing cluster as a session store, so web servers will request session data from a central Hazelcast cluster, helping your development operations team save maintenance across your company.

300ms to 2ms
Latency reduction in inventory fulfillment
For top 10 retailer in US

298% decrease
Time to commit to purchase delivery
Drive Customer Satisfaction at Scale

Reliable Scalability to Match Demand

Drive customer satisfaction to higher levels

Through web session clustering, the most important part of your business (people spending money) is always on, and always available.

Speed that drives innovation

In-memory speed supported by constant availability opens up new opportunities for service innovation across nearly all facets of your organization.

Deliver a consistent customer experience

In-memory speed enables back-end infrastructure to constantly adapt to changing conditions with no noticeable effect at the application (customer) layer.

Related Resources