Cookie Consent by Free Privacy Policy Generator Multi-Region ASP.NET Session State Provider for NCache

Multi-Region ASP.NET Session State Provider for NCache

Many ASP.NET applications today are deployed in multi-region (multi-data center) deployments, either in the Cloud or on-premises. With these applications, you often need to redirect users from one region (data center) to another. However, you cannot afford to lose any ASP.NET Session State in the process.

Such multi-region deployments usually prefer to keep user sessions in the same region where they were created. Essentially, they do not engage in cross-region load balancing at the user request level. But, quite frequently, you need to bump users to other regions for the following reasons:

  • Balance the load across regions if one region is overwhelmed
  • Bring down a region for maintenance

You will have to do this a way where ASP.NET Session State is not lost. One way to solve this problem is by replicating all your ASP.NET sessions to multiple regions. NCache provides a WAN Replication feature for this.

However, in many scenarios, replicating all ASP.NET sessions across regions may not be necessary—especially if you're only shifting 10–20% of the users. In such cases, you may simply want the ASP.NET Session State to move or follow the user when they are redirected from one region to another. This makes the NCache provider an ideal cost-optimization strategy for multi-region architectures that do not require full data synchronization.

Feature Full WAN Replication Multi-Region Session Provider
Strategy Active-Active Synchronization On-Demand Migration
Bandwidth Usage High (Constant background sync) Minimal (Only moves redirected users)
Primary Goal Global Disaster Recovery (DR) Regional Load Balancing & Maintenance
Implementation Server-side Bridge configuration Client-side web.config settings
Best For Application Data / Common State ASP.NET Session State (10-20% redirection)

The NCache provider has the intelligence to handle all such cases. It lets you specify all the regions in your web.config file, and then when a user is redirected to another region, their ASP.NET session is moved from the source region distributed cache to the destination region distributed cache.

NCache is an extremely fast and scalable Open Source distributed cache for .NET. It handles extreme transaction load by allowing you to add more cache servers at runtime and scale linearly. NCache also provides intelligent cache replication so you don't lose any ASP.NET Session State if a web server or a cache server goes down.

NCache architecture showing ASP.NET session migration between primary and secondary regional caches via WAN for uninterrupted user continuity.
NCache Multi-Region ASP.NET Session State flow using primary and secondary cache logic.

The NCache Multi-Region Session Provider uses a "mirrored" logic to maintain session continuity across global data centers. This allows you to define one primary and multiple secondary ASP.NET Session State caches in your ASP.NET web.config as follows. Please note that for each region, the "primaryCache" is different.

<ncache>
  <sessionLocation>
    <primaryCache id="LondonCache" sid-prefix ="LDC"/>
    <secondaryCache id="NewYorkCache" sid-prefix="NYC"/>
    <secondaryCache id="TokyoCache" sid-prefix="TKC"/>
  </sessionLocation>
</ncache>

All ASP.NET sessions are originally stored in their "primaryCache". Then, when the user is bumped to another region, the Multi-Region ASP.NET Session State Provider for NCache in that region notices that this ASP.NET Session is from another region. And, it connects to the corresponding "secondaryCache" and moves the ASP.NET Session to its "primaryCache" so it is available from here.

Benefits of Multi-Region ASP.NET Session State Provider for NCache

First of all, there is no programming required to use NCache as your Multi-Region ASP.NET Session State Provider. You simply modify your web.config and specify NCache as your Session State Provider (SSP). Refer to the page on configuring Multi-Region ASP.NET Session State Provider. The NCache Multi-Region Session Provider optimizes application performance by eliminating WAN replication overhead and ensuring 100% session persistence during cross-region failovers. Key benefits include:

  1. WAN Replication Not Needed: Since most ASP.NET Sessions are not going to be referenced in more than one region. WAN Replication has a bandwidth consumption cost associated with it. Thus, it is more appropriate for application data cache.
  2. Cross-Region High Availability: You can now bring down a data center without affecting any of its users negatively. Just redirect all of them to other regions, and NCache moves their ASP.NET Sessions seamlessly.
  3. Cross Region Scalability: If any region is getting overwhelmed, you can redirect not only new users but also existing ones to other regions without losing their ASP.NET Sessions. NCache moves their ASP.NET Sessions seamlessly.

What to Do Next

Frequently Asked Questions (FAQ)

No, NCache acts as a specialized Session State Provider (SSP) that is implemented entirely through web.config updates, allowing for seamless integration without modifying your application source code.

When a user is redirected, the NCache provider identifies that the session belongs to a different data center using a sid-prefix. It then connects to the source region's secondary cache and moves the session data to the local primary cache to ensure user continuity.

While NCache supports full WAN Replication, the Multi-Region Provider is often a more cost-effective strategy because it only moves session data for the 10-20% of users who are actually redirected, significantly reducing cross-region bandwidth consumption.

NCache uses a unique session ID prefix, known as a sid-prefix, which is assigned to each region in the web.config file. When a user is redirected, the provider checks this prefix to determine the source region and then pulls the session from the corresponding secondary cache.

© Copyright Alachisoft 2002 - . All rights reserved. NCache is a registered trademark of Diyatech Corp.