Interface SnapshotStore

All Known Implementing Classes:
DefaultSnapshotStore, NoOpSnapshotStore

public interface SnapshotStore
Interface for managing snapshots of aggregates in an event-sourced system.

Snapshots are serialized representations of an aggregate's state at a certain point in time (i.e., after a certain sequence number). They allow the system to avoid replaying the entire event history for aggregates with large event logs.

This interface defines methods for storing, loading, and deleting such snapshots. Snapshots are typically used in combination with AggregateRepository and EventStore to optimize aggregate loading.

Usage of this interface is optional—if no snapshot is found, the aggregate is reconstructed from its full event history.

  • Method Details

    • storeSnapshot

      <T> CompletableFuture<Void> storeSnapshot(Entity<T> snapshot)
      Stores a new snapshot for the given aggregate entity.

      The snapshot typically contains the latest known state and metadata such as the aggregate ID and sequence number. Storing a snapshot will overwrite any existing snapshot for the same aggregate ID.

      Type Parameters:
      T - The aggregate root type.
      Parameters:
      snapshot - The aggregate entity to be stored as a snapshot.
      Returns:
      A CompletableFuture indicating whether the operation completed successfully.
    • getSnapshot

      <T> Optional<Entity<T>> getSnapshot(Object aggregateId)
      Retrieves the most recent snapshot for a given aggregate ID, if available.
      Type Parameters:
      T - The expected type of the aggregate.
      Parameters:
      aggregateId - The ID of the aggregate for which to retrieve a snapshot.
      Returns:
      An Optional containing the aggregate snapshot if present, otherwise empty.
    • deleteSnapshot

      CompletableFuture<Void> deleteSnapshot(Object aggregateId)
      Deletes the snapshot for the specified aggregate ID.
      Parameters:
      aggregateId - The ID of the aggregate whose snapshot should be deleted.
      Returns:
      A CompletableFuture indicating completion of the deletion operation.