Stores
A projection keeps its read models in a store, chosen by the store annotation on the projection class.
Each store annotation is also a Spring @Component, so the projection class is an ordinary bean; see The listener.
The framework has three stores.
Comparison
| In-memory | JPA | Query (experimental) | |
|---|---|---|---|
Annotation |
|
|
|
Starter |
every CQRS starter, such as |
|
|
Read models live |
on each instance’s heap |
in the application’s own entity table |
in the framework’s tables in the application’s database |
Survives a restart |
no: rebuilt on every start |
yes |
yes |
Instances |
every instance, each with its own read models |
shared by partition |
shared by partition |
Error handler |
always halts |
configurable with |
configurable with |
Can be an upstream |
no |
yes, while its read-model topic is written |
yes |
Repository |
|
the application’s own |
|
How to choose
-
Use the JPA store for read models that must persist.
-
Use the in-memory store for small read models that are cheap to rebuild, and in tests.
-
The query store is experimental.
Ad-hoc is not a store
A projection marked @AdHoc can also be materialized on demand, beside any store annotation; it keeps its store and keeps running from it.
See Ad-hoc projections.
Serving read models over HTTP
To serve the read models of any store over HTTP, see Read models over HTTP.