C# & ASP.NET Core 8.0 MVC: HttpContext.Session Scalability

164 Views Asked by At

I'm using HttpContext.Session in an ASP.NET Core 8 MVC website.

How scalable is this? Is the data storage limitation based on the RAM of the server?

1

There are 1 best solutions below

2
Jalpa Panchal On BEST ANSWER

HttpContext.Session is generally capable and it also depend which way you are storing the session. let's say if you are storing the session with In-Memory Store. by default, session state is stored in the server's memory. While this is fast, it's not scalable across multiple servers because the session data is local to a single server. This means that if you're using a load balancer, a user's subsequent requests might not hit the same server, and their session data could be lost unless sticky sessions are enabled. The scalability in this scenario is limited by the RAM available on the server.

if you are using Distributed Cache Store like redis or SQL Server. This approach stores session data in a shared cache, which can be accessed by all instances of the web application, regardless of which server handles the request. This setup is more scalable and can handle more users as the session data is not tied to the memory of a single server.