Skip to content

Commit 927571b

Browse files
committed
Add clarification for prod usage of MemoryStore
Closes #30
1 parent 93a11ae commit 927571b

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

src/memory_store.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,25 @@ use std::{collections::HashMap, sync::Arc};
77
/// persistance, this session store is ephemeral and will be cleared
88
/// on server restart.
99
///
10-
/// # ***DO NOT USE THIS IN A PRODUCTION DEPLOYMENT.***
10+
/// # ***READ THIS BEFORE USING IN A PRODUCTION DEPLOYMENT***
11+
///
12+
/// Storing sessions only in memory brings the following problems:
13+
///
14+
/// 1. All sessions must fit in available memory (important for high load services)
15+
/// 2. Sessions stored in memory are cleared only if a client calls [MemoryStore::destroy_session] or [MemoryStore::clear_store].
16+
/// If sessions are not cleaned up properly it might result in OOM
17+
/// 3. All sessions will be lost on shutdown
18+
/// 4. If the service is clustered particular session will be stored only on a single instance.
19+
/// This might be solved by using load balancers with sticky sessions.
20+
/// Unfortunately, this solution brings additional complexity especially if the connection is
21+
/// using secure transport since the load balancer has to perform SSL termination to understand
22+
/// where should it forward packets to
23+
///
24+
/// Example crates providing alternative implementations:
25+
/// - [async-sqlx-session](https://crates.io/crates/async-sqlx-session) postgres & sqlite
26+
/// - [async-redis-session](https://crates.io/crates/async-redis-session)
27+
/// - [async-mongodb-session](https://crates.io/crates/async-mongodb-session)
28+
///
1129
#[derive(Debug, Clone)]
1230
pub struct MemoryStore {
1331
inner: Arc<RwLock<HashMap<String, Session>>>,

0 commit comments

Comments
 (0)