Sitecore, xDB and Session Providers

Update 29/3/2016
I tried the described DistributedCacheSessionStateStoreProvider on a recent project but unfortunately I had to revert to the SQL Server session provider because of some stability issues. These issues may have been corrected in later versions of Sitecore and Sitecore Azure.

The Situation

  • Sitecore 8 with xDB cloud
  • Deployed to Microsoft Azure PaaS - NOT using the Sitecore Azure Module.
  • Highly available with 2+ Content Delivery servers

The Problem

  • Given that we have more than 1 Content Delivery server we need to store Session Out of Process (InProc is not an option)
  • We would like to keep the infrastructure simple. My preference was to use Redis cache which is offered as a service in Microsoft Azure.
  • Unfortunately the Sitecore documentation states that only SQL Server and MongoDB are supported as Session State stores when you are using xDB.
  • Both SQL Server and MongoDB are complicated infrastructure wise. Even SQL Azure is not an easy option here. I'll explain if needed in the comments! :)

Quick answer

When deploying Sitecore 8.0+ with xDB you cannot use Redis and the community Redis session state provider as it does not support Session_End.

The Session_End event is used by Sitecore to flush session information to xDB when a session ends.

Sitecore promotes two options for storing session: SQL Server and MongoDB.

Sitecore also have an undocumented "option" to use Azure InRole (AppFabric) cache. This is how they make their Sitecore Azure (PaaS) module work. The latest version of Sitecore Azure Module with Sitecore 8 currently uses AppFabric. Even though Microsoft prefer that you use Redis on Azure, it is not an option with Sitecore and xDB.

Long answer

As of Sitecore 8.0+ you need a session provider that supports Session_End if you want to use xDB. Sitecore have made an odd design decision here.

Basically zero session providers support this except for InProc. This is entirely logical and is intended by Microsoft. I can tell you why over a beer.

Because no "standard" session providers support Session_End, Sitecore have had to create their own versions of the SQL Server and MongoDB session providers which provide this event. If you reflect the code you will see a timer-based, polling implementation which "fakes" these Session_End events. These are the only "supported" session options you can use with Sitecore and xDB. You CANNOT use the community Redis session provider.

For their Sitecore Azure module, Sitecore have created a new session provider in place of the DistributedCacheSessionStateStoreProvider. It still uses In-Role (AppFabric) cache, but it has the same polling implementation as above so that it can support Session_End. This session provider is undocumented.

If you want to try and use this session provider yourself, it is included in the Sitecore Azure package and is called: Sitecore.Azure.SessionStateProviders.AzureInRoleCacheSessionStateProvider. I am going to give this a go. I'll post my success or failure!

An exercise for people following along at home would be to build your own wrapper around the Redis Session provider which adds in Session_End support just as Sitecore have done for SQL Server and MongoDB. This would likely come with its own set of issues...

comments powered by Disqus