Add optional snapshot support for live models#24
Merged
Conversation
Design proposal that mirrors aggregate snapshotting techniques for live models (read models). Reuses SnapshotCapable and SnapshotStorage SPI, adds LiveModelSnapshotSpecification builder API, and modifies ProjectLiveModelCommand to load/save snapshots around projection. https://claude.ai/code/session_01CxJGnsJcX4mJtMxGHrWqH3
…rage SPI Mirrors the aggregate snapshotting approach for live models (read models projected on-demand). Live models that implement SnapshotCapable<T> can now be configured with a SnapshotStorage at build time to cache their projected state, avoiding full event replay on subsequent reads. API changes: - SnapshotCapable: add key(String, Object...) overload for live model identity based on constructor params (existing Tags-based key unchanged) - LiveModelSpecification: add snapshots(SnapshotStorage) entry point - New LiveModelSnapshotSpecification: fluent builder with eventCountThreshold, readAndWrite/readOnly/writeOnly modes Implementation: - ProjectLiveModelCommand/Unbounded: load snapshot before projection (Projector.startingAfter), save after if threshold met - ReadModelModule: LiveModelInfo record holds per-model snapshot config and Micrometer counters (snapshot.read.count, snapshot.write.count) - LiveModelSnapshotSpecificationImpl: reuses SnapshotSpecificationImpl's READ_AND_OR_WRITE enum Tests: - LiveModelSnapshotTest: snapshot save/load lifecycle, version compatibility, readOnly/writeOnly modes, no-snapshot backward compat https://claude.ai/code/session_01CxJGnsJcX4mJtMxGHrWqH3
Explicitly cast null to (Tags) in key() calls to avoid ambiguity with the new key(String, Object...) overload for live model snapshots. https://claude.ai/code/session_01CxJGnsJcX4mJtMxGHrWqH3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Extends the existing snapshot infrastructure to support live models, mirroring the snapshotting pattern already used by aggregates. Live models can now optionally load from and save snapshots to avoid replaying their entire event history on every read.
Key Changes
API additions (
sliceworkz-eventmodeling-api):key(String, Object...)overload toSnapshotCapable<T>to support constructor-parameter-based snapshot keys for live models (complementing the existing Tags-based key for aggregates)LiveModelSnapshotSpecification<D,I,O>interface providing fluent API for snapshot configuration (mirrorsSnapshotSpecificationfor aggregates)snapshots(SnapshotStorage)entry point toLiveModelSpecification<D,I,O>Implementation (
sliceworkz-eventmodeling-impl):LiveModelSnapshotSpecificationImplclass implementing the snapshot specification builderLiveModelSpecificationAccessor<D>interface for internal access to snapshot configurationReadModelModuleto track snapshot configuration per live model via newLiveModelInforecord, replacing simple class collectionProjectLiveModelCommandandProjectLiveModelUnboundedCommandto:BoundedContextBuilderImplto passLiveModelSpecificationImplobjects toReadModelModuleTests (
sliceworkz-eventmodeling-tests-inmem):LiveModelSnapshotTestclass with comprehensive test coverage:Implementation Details
SnapshotStorage<T>SPI with zero changesreadModelName/param1/param2/...(customizable viakey()override)readAndWrite()(default),readOnly(),writeOnly()SnapshotCapableimplementation work exactly as beforehttps://claude.ai/code/session_01CxJGnsJcX4mJtMxGHrWqH3