Skip to content

Commit 9343e0b

Browse files
Explain the Problem
Issue gh-2295
1 parent 0e2d76b commit 9343e0b

File tree

5 files changed

+40
-0
lines changed

5 files changed

+40
-0
lines changed
Binary file not shown.
Loading
Binary file not shown.
Loading

spring-session-docs/modules/ROOT/pages/index.adoc

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
= Spring Session
2+
23
Rob Winch; Vedran Pavić; Jay Bryant; Eleftheria Stein-Kousathana
4+
35
:doctype: book
46
:indexdoc-tests: {docs-test-dir}docs/IndexDocTests.java
57
:websocketdoc-test-dir: {docs-test-dir}docs/websocket/
@@ -15,6 +17,44 @@ It also provides transparent integration with:
1517
* xref:web-socket.adoc#websocket[WebSocket]: Provides the ability to keep the `HttpSession` alive when receiving WebSocket messages
1618
* xref:web-session.adoc#websession[WebSession]: Allows replacing the Spring WebFlux's `WebSession` in an application container-neutral way.
1719
20+
== Understanding the Problem That Spring Session Solves
21+
22+
When a user interacts with a web application, the server creates a session to keep track of their activity.
23+
This session may store information such as user preferences, login status, and shopping cart contents.
24+
However, sessions can be problematic in a distributed environment, as they are typically stored on the server's memory.
25+
26+
To better understand the problem that Spring Session solves, let's first visualize the following diagram:
27+
28+
.In-Memory Sessions
29+
image::inmemory-sessions.png[In-Memory Sessions]
30+
31+
In the diagram above, each Spring application is storing its sessions in a place where only themselves can access them, usually in the server's memory, but this can be a problem in a distributed environment.
32+
Imagine a situation where Spring App #2 receives a request with Session #3, the application will not be able to read the session data because it is stored in Spring App #1's memory.
33+
To solve this problem we need to implement some kind of Shared Session Storage as we can see in the diagram below:
34+
35+
.Shared Session Storage
36+
image::shared-session-storage.png[Shared Session Storage]
37+
38+
With the above setup, the sessions become available for every application that has access to the session storage.
39+
40+
Spring Session provides a layer of abstraction between the application and the session management.
41+
It allows the session data to be stored in various persistent stores, such as relational databases, NoSQL databases, and others.
42+
43+
With Spring Session, you can use the same API to manage sessions, regardless of the persistent store used.
44+
This makes it easier to switch between stores without changing the application code.
45+
Spring Session also provides features such as session expiry and cross-context communication between different web applications.
46+
47+
Overall, Spring Session simplifies the management of user sessions in web applications, making it easier for you to focus on building the core features of their applications.
48+
49+
Here are some common use cases for Spring Session:
50+
51+
- Distributed web applications: If you have a web application distributed across multiple servers, managing user sessions can be challenging.
52+
Spring Session can help by storing the session data in a shared database or Redis, allowing all servers to access and update session data.
53+
54+
- Session scalability: In a large web application with many concurrent users, storing sessions in memory on the server can lead to scalability issues.
55+
Spring Session allows you to store session data in a persistent store, improving scalability and reducing the risk of out-of-memory errors.
56+
57+
- Session backup and recovery: Storing session data in a persistent store can also provide a mechanism for backing up and recovering session data in case of server failure or downtime.
1858

1959
[[community]]
2060
== Spring Session Community

0 commit comments

Comments
 (0)