The In-Memory Event Store
We provide a built-in, fully thread-safe in-memory adapter calledInMemoryEventStore. It holds committed events inside an internal memory map protected by a reader-writer lock (Arc<RwLock>).
It is perfect for:
- Local development and rapid prototyping.
- Fast integration testing where you don’t want the overhead of starting SQLite or PostgreSQL databases.
- Proving out core business workflows.
Initializing the Store
To set up an in-memory event store for ourBankAccount aggregate, import the module and initialize it:
How It Operates
Under the hood, when a transaction occurs, theRepository requests the in-memory store to:
- Load all committed event envelopes matching a specific Aggregate ID.
- Verify if the stream’s current in-memory revision matches what the client expects (Optimistic Concurrency Control).
- If valid, append the new envelopes to the aggregate’s vector of events inside the lock.