ayasha
ayasha

Reputation: 1251

Redis Session State Provider manage fallback

I use Redis as Session State Provider but since I have many users sometimes it happens that Redis goes down. So I would like to have a default Session State Provider to use in case the first one goes down.

Is this possible? Any other solutions?

Thanks

Upvotes: 2

Views: 1069

Answers (2)

Mark Waterman
Mark Waterman

Reputation: 961

ASP.NET's session pipeline doesn't support falling back to a different session provider, so the fallback functionality would have to be baked into the Redis session state provider. But the Redis provider only talks to Redis, so you'd have to do this yourself, either in your own fork of the project or by creating your own custom session provider that inherits from SessionStateStoreProviderBase and wraps access to the RedisSessionStateProvider (along with whatever fallback storage logic you'd like to use if your provider detects a Redis outage).

But you're looking a big fat mess now: where should you temporarily store the data (An in-process cache? Now you're talking sticky sessions. SQL Server? Yet another server to manage)... And, once Redis comes back up, how do you repopulate it with the active sessions from your temporary storage? There are lots of problems to think through, and it's no wonder that Microsoft doesn't support it.

So your best bet, as @MatíasFidemraizer alluded to, is to focus your energy on improving your Redis deployment so that it can handle your load and also set up Master-Slave replication with Redis Sentinel to do automatic failover. If that's too much work then there are a number of commercial solutions that'll do the heavy lifting of failover for you (the company I work for has a dead-simple product called ScaleOut SessionServer)

Upvotes: 1

Matías Fidemraizer
Matías Fidemraizer

Reputation: 64943

since I have many users sometimes it happens that Redis goes down

I doubt that this should the reason behind the scenes. Do you have enough RAM? There could be a lot of reasons but I doubt that the issue is "many users" unless you're Google, Twitter o some site with extreme high traffic, and after all, Redis is designed for that use case too...

So I'll skip the part of how you would switch state providers and I'll go to:

Any other solutions?

The answer is Redis Sentinel (follow this link to learn more about it).

From the official docs:

Redis Sentinel provides high availability for Redis. In practical terms this means that using Sentinel you can create a Redis deployment that resists without human intervention to certain kind of failures.

Upvotes: 0

Related Questions