Skip to content

Add optional snapshot support for live models#24

Merged
vanrogu merged 3 commits intodevelopfrom
claude/live-model-snapshotting-ichqU
Feb 12, 2026
Merged

Add optional snapshot support for live models#24
vanrogu merged 3 commits intodevelopfrom
claude/live-model-snapshotting-ichqU

Conversation

@vanrogu
Copy link
Member

@vanrogu vanrogu commented Feb 12, 2026

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):

    • Added key(String, Object...) overload to SnapshotCapable<T> to support constructor-parameter-based snapshot keys for live models (complementing the existing Tags-based key for aggregates)
    • New LiveModelSnapshotSpecification<D,I,O> interface providing fluent API for snapshot configuration (mirrors SnapshotSpecification for aggregates)
    • Added snapshots(SnapshotStorage) entry point to LiveModelSpecification<D,I,O>
  • Implementation (sliceworkz-eventmodeling-impl):

    • New LiveModelSnapshotSpecificationImpl class implementing the snapshot specification builder
    • New LiveModelSpecificationAccessor<D> interface for internal access to snapshot configuration
    • Modified ReadModelModule to track snapshot configuration per live model via new LiveModelInfo record, replacing simple class collection
    • Updated ProjectLiveModelCommand and ProjectLiveModelUnboundedCommand to:
      • Load snapshots before event replay (if configured and read mode enabled)
      • Resume projection from the snapshot's last event reference
      • Save new snapshots after projection if event count threshold is met (if write mode enabled)
    • Wired snapshot configuration through BoundedContextBuilderImpl to pass LiveModelSpecificationImpl objects to ReadModelModule
    • Added Micrometer metrics for snapshot read/write operations per live model
  • Tests (sliceworkz-eventmodeling-tests-inmem):

    • New LiveModelSnapshotTest class with comprehensive test coverage:
      • Snapshot creation and loading behavior
      • Event count threshold triggering
      • Version mismatch handling (full replay on version change)
      • Read-only, write-only, and read-write modes
      • Backward compatibility (live models without snapshots work unchanged)

Implementation Details

  • Reuses existing SnapshotStorage<T> SPI with zero changes
  • Snapshot keys for live models: readModelName/param1/param2/... (customizable via key() override)
  • Event count threshold (default 100) triggers snapshot creation
  • Three modes: readAndWrite() (default), readOnly(), writeOnly()
  • Fully backward compatible: live models without SnapshotCapable implementation work exactly as before
  • Metrics follow the same pattern as aggregate snapshotting

https://claude.ai/code/session_01CxJGnsJcX4mJtMxGHrWqH3

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
@vanrogu vanrogu merged commit 0d2bb16 into develop Feb 12, 2026
@vanrogu vanrogu deleted the claude/live-model-snapshotting-ichqU branch February 13, 2026 19:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants