Skip to content

Read Models

Read models are documented in the shared Chronicle docs so the model stays consistent across clients.

For JVM syntax, see the annotation reference and EventStore API reference.

Beyond getInstanceByKey, the Kotlin client’s store.readModels exposes a richer surface for reading and managing read model instances:

MemberUse it for
getInstancesEvery instance, replaying events in-process.
getSnapshotsByIdSnapshots of a read model grouped by correlation id.
watchA Flow of changesets for a read model — a live view.
dehydrateSessionReleasing session-scoped state for an instance.
release/releaseManyDecrypts @Pii properties, one or many.
materializedPaginated, server-materialized reads — see below.

To react to changes without collecting a Flow yourself, write a convention-dispatched reactor instead — see Read Model Reactors.

getSnapshotsById and watch both deserialize straight into the read model type you ask for — getSnapshotsById(EmployeeProfile::class, key) returns List<ReadModelSnapshot<EmployeeProfile>>, and watch(EmployeeProfile::class) returns Flow<ReadModelChangeset<EmployeeProfile>> — no manual JSON parsing either way.

val employees = store.readModels.getInstances(EmployeeProfile::class)
employees.forEach { employee ->
println("${employee.firstName} ${employee.lastName}")
}

store.readModels.materialized provides paginated access to instances a sink has already materialized server-side, instead of replaying events in-process:

val page = store.readModels.materialized.getInstances(
EmployeeProfile::class,
skip = 0,
take = 50
)
store.readModels.materialized
.observeInstances(EmployeeProfile::class, skip = 0, take = 50)
.collect { updatedPage -> /* re-render whenever the page changes */ }

getInstances returns a single page; observeInstances returns a Flow that emits a fresh page every time the underlying data changes.