Memory Store
The MemoryStore is an in-memory implementation of the Store interface that provides per-session key-value storage backed by a thread-safe ConcurrentHashMap.
It is lightweight, fast, and suitable for single-node deployments, development environments, and scenarios where session data does not need to be shared across multiple server instances.
Key characteristics
Local per-session storage — each connection receives its own store instance
Thread-safe access — supports concurrent reads/writes using
ConcurrentHashMapEphemeral data — values exist only in JVM memory and are lost on restart or failure
No cross-node sharing — data is not distributed between servers
Zero external dependencies — simplest possible
Storeimplementation
How it works
set(key, value)stores a value in memory scoped to the sessionget(key)retrieves the stored value, ornullif none existshas(key)checks key presence without reading the valuedel(key)removes a single entrydestroy()clears all entries, typically called when the client disconnects
Advantages
👍 Fast, low-latency access
👍 No external services required
👍 Ideal for development and local testing
👍 Works well with any EventStore for hybrid deployments
(e.g., MemoryStore + KafkaEventStore or MemoryStore + RedisStreamEventStore)
Limitations
ℹ️ Not distributed — values are not synchronized across nodes
ℹ️ Not persistent — data vanishes on server restart or crash
ℹ️ Not suitable for horizontal scaling unless combined with a distributed StoreFactory implementation
Summary
MemoryStore provides local, ephemeral per-session data storage, ideal for single-node setups and development. Can be combined with any distributed EventStore when distribution of events is required without distributed storage.
Last updated
Was this helpful?