Snapshotting of Events doesn't improves performance

Hi team,
I have implemented snapshotting for my Aggregates by configuring EmbeddedEvnetStore Configuration for MongoDB. (Keeping snapshot serializer Default i.e. XStream)

  return MongoEventStorageEngine.builder()
                    .mongoTemplate(DefaultMongoTemplate.builder()
                            .mongoDatabase(mongoClient).build())
                    .eventSerializer(JacksonSerializer
                            .defaultSerializer())
                    .build();

Now, Snapshots are created fine, but for a new command still replaying the previous events. And because of that, In EventSourcinghandler there is a logic that executes for previous events to rebuild the state of an Aggregate. It takes time for execution.

    @EventSourcingHandler
    public void on(final GroupCreatedEvt evt)
            throws InvalidProtocolBufferException {

        this.cmId = evt.getId();
        final GroupCreated groupCreated = ProtoSerDer.fromJsonToProtoBuf(
                evt.getGroupCreated(), GroupCreated.class).orElseThrow();
        this.data.created(groupCreated);
    }

Shouldn’t a new command rebuilds the state from the created snapshots?
It seems, when applying a new event it replays the events from the domain events.
Then what is the significance of snapshotting?
Is there any further configuration required for utilizing snapshots?

Already handled here.

1 Like