Multi-site Java Session Support
NCache provides multi-site session persistence which can be used to manage Java servlet sessions across multiple web farms (that are geographically separated) and if you do not want to replicate sessions across WAN because of bandwidth consumption cost.
To understand multi-site session persistence, consider Java servlet applications that run in load-balanced web server farms whose span is over multiple regions. A load balancer can redirect clients to different regions depending on user traffic. In this situation, to cache sessions, a clustered cache is required so that sessions are replicated across regions. This approach may not be suitable mainly because of bandwidth consumption due to sessions replication across WAN. Also, it may raise performance issues because caching nodes are geographically separated.
To solve these problems, NCache presents the concept of multi-site sessions. To cache the sessions in a geographically separated web farms application, you can configure separate caches in each region. Let's suppose you have four regions, each configured with separate caches as CR-1, CR-2, CR-3 and CR-4. Each clustered cache has its own set of clients (Java servlet) as a web farm. Each client will configure NCache session servlet filter. You need to specify the primary cache (current region cache) and a set of secondary caches (list of other region caches) along with the user defined prefixes against each cache name.
This configuration will be loaded upon initialization of the NCache session provider filter. In this way, each client will be aware of other region caches. Session ID created by NCache session provider will be based on each region primary cache prefix i.e. prefix of primary cache will be appended in session IDs of that region. These clients will add, update, and get sessions mostly from their own clustered cache i.e. primary cache. However, at times a client request might be sent to the web farm of another geographical location for load balancing. Now, NCache will identify the request from its primary cache prefix and allow the user requests to access the same session from previous cache.
To understand this, consider a request route to a web farm of CR-2 region cache. In this situation, NCache extracts session ID prefix which will be CR-1 and will search its cache ID in its own secondary caches list. As all regions clients will have a set of all other region caches as secondary caches, NCache will fetch this session from CR-1 cache. NCache will update this session's ID by appending its current primary cache prefix i.e. CR-2 and updating it in the current primary cache (CR-2) to serve future requests.
Let's suppose a client makes a request that passes through the Load Balancer. Suppose the session request is passed to the Web Server1 within a web farm based on system load. Once the request reaches, a session is created here with Web Server1 prefix appended with session ID and saved in primary cache for this web farm, in this case Replicated Cache1.
When Load Balancer routes the same client to Web Farm2, NCache analyzes the session prefix. With the help of this prefix it fetches the session from Replicated Cache1 even though it belongs to Web Farm1. This allows you to have two or more active data centers, keep most of the traffic to its own data center but occasionally overflow to the other data center if you want. And you can also bring down one of the data centers without causing any interruptions for the users because their sessions will be accessible by other data centers. Or we can say that if one of the web farms goes down for any reason, other web farms will start accessing user sessions from that region cache and eventually the whole session data will be moved to next region cache. In this way we can prevent session data lost.
NCache provides a no-code change option for Java based web applications to store sessions in NCache by implementing session module nc-sessionprovider.jar as a JSP Servlet Filter. In order to use NCache Java session module, you must be running a Servlet 2.3 or later compatible container (web server). The user only needs to reference a few libraries and add a filter in web.xml of the application so that all the requests will come to the application through NCache. Following J2EE/Jakarta platforms are supported:
- Web Logic