PHP Event Sourcing Snapshoting
In general having streams in need for snapshots may indicate that our model needs revisiting. We may cut the stream on some specific event and begin new one, like at the end of month from all the transactions we generate invoice and we start new stream for next month. However if cutting the stream off is not an option for any reason, we snapshot aggregate state at given point of time, so we can skip previous events. This process continues on predefined threshold, like every 1000 events.

Setting up

To set up snapshots we will define ServiceContext configuration.
public function aggregateSnapshots()
$snapshotGivenAggregates = [Ticket::class, Basket::class];
$threshold = 1000;
return EventSourcingConfiguration::createWithDefaults()
->withSnapshots($snapshotGivenAggregates, $threshold);
Ecotone make use of Document Store to store snapshots, by default it's enabled with event-sourcing package. If you want to clean the snapshots, you can do it manually. Snapshots are stored in aggregate_snapshots collection.