Session storage is one of the cornerstones of a scalable web application. Couchbase Server is a performant, scalable, and flexible session storage choice. Beyond simply storing and retrieving session quickly, Couchbase Server also provides tools for exploring and mining session data for valuable insights. There are also open-source projects for more easily integrating Couchbase with your web framework of choice. So, if you’re building web applications and need a scalable session store, read on, because we’ve just published a tutorial that will help you get started with ASP.NET session storage.

Side note: the documentation team at Couchbase has been hard at work creating a new searchable “tutorials” section. It’s open source, it looks great, and I’m really excited about it! Keep an eye on that page, because there are a lot more tutorials to come this year!

Session storage

When a user logs in to or visits a site, they start a “session”. The session and the user are correlated by giving a cookie to the user’s web browser with a lookup value that directly corresponds to session storage on the server side. ASP.NET and ASP.NET Core often store this data in memory on the web server.

For small sites and/or single server deployments, that might be okay. For larger deployments, it could be problematic for at least two reasons:

  • If the web server goes down or is restarted, that session information is wiped out.
  • “Sticky sessions” mean that a user is “stuck” to a single server, which can lead to unbalanced loads over time.

Another approach is to store session data separately from the web servers.

Web farm and session storage architecture

A web farm will sit behind a “load balancer”. This load balancer will direct requests to available ASP.NET servers. If session data live elsewhere, the load balancer is free to choose any server to direct the request.

Session storage architecture

Exploring session data

There are many choices for tools to support session storage, but Couchbase Server offers some unique capabilities:

Memory-first (or memory only) storage. Once a Session starts, it is often read or written on every page request. With Couchbase, you can read/write data at the speed of memory.

Ease of scaling. Couchbase’s shared-nothing architecture means that scaling up is not complicated. There’s no single “master” node to constrain operations.

Data insights. Couchbase’s N1QL query language, as well as the new Analytics service, make it easy for you to analyze your enterprise’s session data in aggregate. You can do this by using the familiar SQL language. Here’s an example from the session storage tutorial of a N1QL query to find the most common items put into a shopping cart:

Next Steps

If you are a .NET developer, you can follow along with the complete session storage tutorial right now. If you are using other frameworks or languages, session storage tutorials are coming soon!

If you have any questions or feedback for this tutorial, you can find me on Twitter @mgroves. As with everything in Couchbase documentation, this tutorial is open source and pull requests for improvements are welcome!

Author

Posted by Matthew Groves

Matthew D. Groves is a guy who loves to code. It doesn't matter if it's C#, jQuery, or PHP: he'll submit pull requests for anything. He has been coding professionally ever since he wrote a QuickBASIC point-of-sale app for his parent's pizza shop back in the 90s. He currently works as a Senior Product Marketing Manager for Couchbase. His free time is spent with his family, watching the Reds, and getting involved in the developer community. He is the author of AOP in .NET, Pro Microservices in .NET, a Pluralsight author, and a Microsoft MVP.

Leave a reply