IBM Cloud Authors: Zakia Bouachraoui, Elizabeth White, Yeshim Deniz, Pat Romanski, Liz McMillan

Related Topics: IBM Cloud

IBM Cloud: Article

Building High-Availability Web Applications - Managing HTTP sessions within clustered WebSphere 5 environments

Building High-Availability Web Applications - Managing HTTP sessions within clustered WebSphere 5 environments

To provide the best performance and availability for WebSphere applications, administrators and developers count on scalability features found in the software, hardware, and networking components that host their WebSphere domain. More than ever, the availability of our Web applications can impact critical business processes.

Recognizing this, WebSphere technologists are implementing high-availability (HA) clusters using WebSphere Application Server Network Deployment Edition v5, hereafter referred to as ND. Along with HA functionality found in databases, Web servers, and operating systems, ND can be implemented to deliver the benefits of HA architecture: increased performance, failover, recovery, and workload management.

Let's now consider the Java applications hosted within WebSphere. Are they affected when the application servers that contain them are cloned? In the development life cycle, did you consider that your code might be deployed into a clustered WebSphere topology? For the servlet and JSP developer, this means that requests to servlets or JSPs might not be serviced by the same application server, even though the requests might all be for the same session.

In this article, I will examine HTTP session management strategies in clustered WebSphere environments from the perspectives of the administrator and the developer. I will make the case for implementing ND's framework for session management as an alternative to client-tier sessions, describing the tracking and persistence functionality that ND delivers.

Client-Tier Session Management
The HTTP session is implicitly stateless; this limitation must be considered when designing an HA solution. One way developers can overcome this limit is by storing the session at the client (browser) and delivering it as part of each server request.

There are several ways developers can store the session data at the client, including URL rewriting, cookies, and hidden HTML form elements. These are not to be confused with ND's session tracking mechanisms. The difference is that ND uses URL rewrites or cookies only to track the session ID. Storing the session in the client means sending all or most of the session data back and forth between the client and the server clone. Here are the major problems found with client-stored session data:

  • Network traffic: In each request to the server, a potentially large amount of session data will be along for the ride. Depending on the implementation, the server might also respond with the entire session. Another drawback is that usually most of the data is unchanged and is unnecessarily exchanged.
  • Varying browser support: When using URL rewriting or cookies to transport an entire session, you might run into size limitations at the client. There aren't standards that specify how long a URL can be or how much data can be stored in a cookie. Each browser enforces different rules.
  • Security: HTML forms can be saved anywhere the browser is rendered. Also, cookie files could be edited and URLs could be altered and pasted into another browser. While it's possible to add encryption, this will mean added complexity and performance overhead.
Since the entire session is part of each HTTP conversation, there is no need for stateful interaction with server clones. In this scenario, it doesn't matter which server clone services the request because the session data is contained in the request.

ND offers the alternative of server-managed sessions through affinity, tracking, and persistence mechanisms. This lets the developer take advantage of server-tier session management, with the added benefits of the HA infrastructure built into ND clusters. The rest of this article describes ND's support and functionality for server-tier session management.

ND Session Affinity
The conversation between a browser and a server clone can contain many exchanges. Since the browser initiates the conversation, the server clone that first services the request must be linked in some way to this new session so that subsequent requests can also be serviced by the same clone. Take, for example, the online shopping cart. As the user shops, items are added to the virtual shopping cart before checkout. This interaction could involve multiple HTTP exchanges. If items in the shopping cart are kept at the server clone, every one of those HTTP exchanges must be serviced by the same clone.

Uniquely identifying this browser-to-server relationship is what's known as session affinity. ND supports session affinity through the plug-in architecture, which defines the transport parameters between the Web server and the server clones. The plug-in parameters are built by the ND administrative server and stored in the plugin-cfg.xml file. When a server cluster is created, ND assigns each clone a unique identifier. Listing 1 shows what it looks like in the plugin-cfg.xml.

Since clone IDs are automatically assigned when the cluster is created, session affinity is enabled by default. The process of matching a session to a clone can impact performance, so if you don't need session affinity, disable it by removing the clone IDs from the plugin-cfg.xml. Also note that the plug-in will bypass session affinity if it doesn't detect session ID as part of the request. I'll discuss later how ND identifies the session and the options we have to track it.

The mechanics of session affinity are pretty straightforward, but it's worth noting that affinity guarantees only that requests for a single session are routed to the same clone. If the clone fails or is shut down, the plug-in will route the request to a different clone. If the alternate clone can't recover the session, then it is lost.

Using our shopping cart example, such a failure will result in an empty cart. To avoid this, ND has session persistence options that make the session recoverable in failover scenarios. But first let's cover session tracking functionality in ND to complete the affinity picture.

ND Session Tracking Mechanisms
In addition to unique clone IDs, establishing affinity requires unique session IDs and an ability to track them in a multipart, browser-to-clone conversation. ND offers three options for tracking the session ID: SSL ID tracking, cookies, and URL rewriting. You can enable more than one tracking mechanism, and ND will resolve them in the following order: (1) SSL session IDs, (2) cookies, and (3) URL rewriting. A good reason to enable more than one mechanism is that each has deficiencies. If you decide to track sessions by SSL ID and the Web server fails, ND can fall back on an alternative tracking mechanism. The great part is that this functionality is built into ND, ready to go. Figure 1 shows ND's session tracking mechanisms.


An advantage of SSL tracking is that it doesn't require any code changes. The SSL ID is negotiated between the browser and the Web server, so even an application server failure won't change the session ID. Keep in mind that SSL IDs are affected by the Web server configuration (httpd.conf for Apache-style Web servers) and this may overlap with ND's session management controls. For example, session timeout is set by the SSLV3TIMEOUT parameter in the Web server, and is also set in ND's session management settings. Another possible conflict might occur if your code contains custom session invalidation routines. Be careful to verify each layer (Web server, app server, Web apps) to ensure one doesn't step on another.

As a tracking mechanism, cookies can be problematic. Many users block cookies out of concern for privacy. Some network administrators filter out cookies at the firewall. Still, beyond any privacy concerns, there are valid technical reasons for avoiding cookies. If cookies are permitted they can easily be manipulated at the client through browser controls or at the file system. Cookie files can be purged, expired, and changed manually. Any of these actions will cause loss of the session ID. If we don't trust cookies to hold session data, then we shouldn't trust cookies to hold the reference (session ID) to the session data either.

URL rewriting is fairly straightforward and involves appending the session ID to the end of a URL. There is a simple code requirement that the servlet or JSP must encode the URL for ND to properly recognize that a URL has a session attached to it.

The following code snippet shows the URL encoding in the servlet:


The following code snippet shows the URL encoding in the JSP:

<%= response.encodeURL(request.getRequestURI())%>

A big advantage for URL rewriting is that it works everywhere. It also supports concurrent sessions for single users, but this could be troublesome if the user pastes the URL of an active session into a new browser instance. The server wouldn't know which browser instance was active. From a code perspective, especially for JSPs, URL rewriting can be awkward. Any page links in the JSP that need stateful session information would need their URLs rewritten. Also off-limits are any static HTML pages, because there's no way to insert the session ID.

The IBMSession Interface
It is quite common for Web applications to store session data at the server in a session object without persistence. This nonpersisted, local session exists only in JVM memory; if it is not persisted through ND, it is not made available outside this JVM and doesn't play a role in the HA infrastructure. Be careful not to confuse in-memory local sessions with ND's memory-to-memory replication. In-memory local sessions are limited to a single server (per the Servlet 2.3 specification), and don't offer recovery options after failover.

Servlet developers using local sessions store information through the HttpSession interface. The HttpSession is obtained through the HttpServletRequest, and is handled in the servlet's doGet() and doPost() methods. The HTTPSession methods to access and update the session include:

HttpSession hsess = req.getSession();
Object o = hsess.getAttribute("sessAttributeName");
hsess.setAttribute("sessAttributeName", sessObject);

The IBMSession interface extends the HTTPSession to add the following functionality: session overflow control, user identity association, and the ability for the developer to force a session to be persisted externally. While the first two fall under the umbrella of ND's session management offerings, it is the session persistence method that is important in a clustered topology. The developer has complete control of when the session gets persisted by calling the sync() method. This level of control is new in ND; previously the persistent store update was deferred until the end of the time interval specified in the session manager's write frequency settings, as shown in Figure 2.


Developers who store session data at the server can easily implement the IBMSession interface, and won't have much work left to achieve a server-tier session management system that supports failover. An added bonus is that very little, if any, code needs to change to implement persistent sessions with ND.

The WebSphere implementation, through the IBMSession interface, includes methods to access the extended functionality:

IBMSession isess = (IBMSession)req.getSession();
if (isess.isOverFlow()) throw new ServletException ...
String userName = isess.getUserName();
isess.setAttribute("sessAttributeName", sessObject);
isess.sync(); // persist externally

Now we can turn our attention toward what ND offers us for session persistence. We've already seen how the IBMSession interface allows the developer to choose exactly when the persistent store is updated, so let's look at the other way that persistent stores get updated, along with the details about ND's persistence mechanisms.

ND Session Persistence Mechanisms
To briefly review, we've identified the session and the server (IDs), associated the two (affinity), and routed the request (plug-in). As we move on and discuss ND's session persistence functionality, keep in mind that ultimately it is the two persistence options that make failover recovery possible for the session.

Figure 3 shows the distributed environment settings in ND's administrative console. Here you can specify either database or memory-to-memory replication. Memory-to-memory replication is new in ND and uses WebSphere internal messaging.


Before the release of ND, database persistence was the only option available. The concept of persisting session objects to a database is fairly straightforward. Usually, when discussing this option, the first question asked is about performance. The general concern is that writing the objects out to a database is slow to begin with, and will collapse under any volume. While it's possible to overload even a very highly tuned system with enough volume, the real problem is the size of the session. When selecting database persistence, you must carefully consider page sizes (if using DB2) and whether to use a multirow schema. A single-row schema means one session object per row. A multirow schema means one session attribute per row. The trade-off is between performance and space in the database. The consensus best practice is to keep the session objects as small as possible and carefully analyze the average session size to determine database structure.

Memory-to-memory replication is a new alternative for persistence released in ND. One of the best reasons to consider this option is that it doesn't require a database. At first look, it might not be a big deal to create and manage a simple database for session persistence; however, the database needs to be part of a clustered solution to avoid a single point of failure.

There are three possible topologies: single replica, dedicated replication server, and peer-to-peer (default). The basic idea is that the session objects are "replicated" in memory between server clones, and the different topologies offer varying degrees of recovery. If a clone fails, the next request is routed through the plug-in, which then, depending on topology, can access a replicated copy of the session. The session size is even more important in memory-to-memory replication than in database persistence. A large session object combined with a high number of users can exhaust JVM heap memory quickly. The performance trade-off comes in the number of servers that participate in replication (based on the three available topologies).

Immediately after a session is persisted, it starts growing stale. Any session updates that happen after the last write won't be recovered in a failover scenario. We must decide between the performance trade-off of low update intervals and an acceptable level of session "freshness." Frequent updates (session synchronization) can hurt server performance. The best strategy is to find the right balance that still keeps your data fresh. In addition to the manual control through the IBMSession interface, you can choose a prepackaged tuning level that doesn't require any code change. The tuning choices are shown in Figure 4.


Since performance is an overriding factor in deciding on a persistence method, load testing is important and can help identify any weakness in an HA design before it is implemented. For many developers and administrators it is difficult to stage the entire HA implementation for testing and proof-of-concept purposes. There are some relatively inexpensive options, however, that can help you build a replica of your HA design. The ND environment described in this article was built using VMware's virtual machine software (www.vmware.com), allowing a single workstation to host software components (Web server, database, WebSphere) in separate virtual machines. To test performance and functionality, Apache's JMeter (http://jakarta.apache.org/jmeter/index.html) was used to simulate HTTP requests.

Developers can build use cases and test them against a planned HA configuration. For example, if you plan on implementing memory-to-memory replication using the default peer-to-peer topology, you might be concerned about the replicated sessions exhausting JVM memory. Such virtualized testing can help validate your choice of persistence methods. Developers can also simulate failover by shutting down server clones or even an entire virtual machine to observe recovery behavior.

WebSphere Application Server ND supplies rich session management support in the areas of session tracking and persistence. Since the hardware, network, and software components on the server side of the topology are usually very reliable, it makes good sense to trust application-critical data, like session data, to the server tier. While this article focuses on the HA aspects of ND session management, it should be noted that there are other session-related controls in WebSphere 5 that we did not cover (check the referenced documents for more information). Developers and administrators are encouraged to take advantage of this functionality to build Web applications that meet the demand for application availability.


  • Wang, H. and Bransford, M. Server Clusters for High Availability in WebSphere Application Server Network Deployment Edition 5.0: http://ibm.com/support/docview.wss?uid=swg27002473
  • IBM WebSphere Application Server v5.0 System Management and Configuration (IBM Redbook): http://publib-b.boulder.ibm.com/Redbooks.nsf/ RedbookAbstracts/sg246195.html?Open

    Performance Tips

    • By default, JSP pages create a session for every page. To avoid creating unnecessary sessions on JSP pages that don't need a session, set the scope to "false" with: <%@page session="false" %>.
    • If session affinity is not required, disable it by removing the clone IDs from the plugin-cfg.xml file to improve performance.
    • If using database persistence, use a dedicated session database. Storing session data in a shared database can adversely affect performance.
    • Build a small-scale replica of the HA topology and conduct functionality and performance validation testing.
    • Keep session objects small. Large session objects can limit options for session persistence topologies and are resource intensive. Limit data stored in the session to a minimum.
  • More Stories By Christopher Delgado

    Chris Delgado is a consultant based in Atlanta, Georgia, working with clients in the areas of WebSphere, Java, and relational databases. Chris is an IBM-certified specialist in WebSphere and DB2 and has worked as a developer and architect for nearly 10 years.

    Comments (1)

    Share your thoughts on this story.

    Add your comment
    You must be signed in to add a comment. Sign-in | Register

    In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.

    IoT & Smart Cities Stories
    Moroccanoil®, the global leader in oil-infused beauty, is thrilled to announce the NEW Moroccanoil Color Depositing Masks, a collection of dual-benefit hair masks that deposit pure pigments while providing the treatment benefits of a deep conditioning mask. The collection consists of seven curated shades for commitment-free, beautifully-colored hair that looks and feels healthy.
    The textured-hair category is inarguably the hottest in the haircare space today. This has been driven by the proliferation of founder brands started by curly and coily consumers and savvy consumers who increasingly want products specifically for their texture type. This trend is underscored by the latest insights from NaturallyCurly's 2018 TextureTrends report, released today. According to the 2018 TextureTrends Report, more than 80 percent of women with curly and coily hair say they purcha...
    The textured-hair category is inarguably the hottest in the haircare space today. This has been driven by the proliferation of founder brands started by curly and coily consumers and savvy consumers who increasingly want products specifically for their texture type. This trend is underscored by the latest insights from NaturallyCurly's 2018 TextureTrends report, released today. According to the 2018 TextureTrends Report, more than 80 percent of women with curly and coily hair say they purcha...
    We all love the many benefits of natural plant oils, used as a deap treatment before shampooing, at home or at the beach, but is there an all-in-one solution for everyday intensive nutrition and modern styling?I am passionate about the benefits of natural extracts with tried-and-tested results, which I have used to develop my own brand (lemon for its acid ph, wheat germ for its fortifying action…). I wanted a product which combined caring and styling effects, and which could be used after shampo...
    The platform combines the strengths of Singtel's extensive, intelligent network capabilities with Microsoft's cloud expertise to create a unique solution that sets new standards for IoT applications," said Mr Diomedes Kastanis, Head of IoT at Singtel. "Our solution provides speed, transparency and flexibility, paving the way for a more pervasive use of IoT to accelerate enterprises' digitalisation efforts. AI-powered intelligent connectivity over Microsoft Azure will be the fastest connected pat...
    There are many examples of disruption in consumer space – Uber disrupting the cab industry, Airbnb disrupting the hospitality industry and so on; but have you wondered who is disrupting support and operations? AISERA helps make businesses and customers successful by offering consumer-like user experience for support and operations. We have built the world’s first AI-driven IT / HR / Cloud / Customer Support and Operations solution.
    Codete accelerates their clients growth through technological expertise and experience. Codite team works with organizations to meet the challenges that digitalization presents. Their clients include digital start-ups as well as established enterprises in the IT industry. To stay competitive in a highly innovative IT industry, strong R&D departments and bold spin-off initiatives is a must. Codete Data Science and Software Architects teams help corporate clients to stay up to date with the mod...
    At CloudEXPO Silicon Valley, June 24-26, 2019, Digital Transformation (DX) is a major focus with expanded DevOpsSUMMIT and FinTechEXPO programs within the DXWorldEXPO agenda. Successful transformation requires a laser focus on being data-driven and on using all the tools available that enable transformation if they plan to survive over the long term. A total of 88% of Fortune 500 companies from a generation ago are now out of business. Only 12% still survive. Similar percentages are found throug...
    Druva is the global leader in Cloud Data Protection and Management, delivering the industry's first data management-as-a-service solution that aggregates data from endpoints, servers and cloud applications and leverages the public cloud to offer a single pane of glass to enable data protection, governance and intelligence-dramatically increasing the availability and visibility of business critical information, while reducing the risk, cost and complexity of managing and protecting it. Druva's...
    BMC has unmatched experience in IT management, supporting 92 of the Forbes Global 100, and earning recognition as an ITSM Gartner Magic Quadrant Leader for five years running. Our solutions offer speed, agility, and efficiency to tackle business challenges in the areas of service management, automation, operations, and the mainframe.