-
-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP: Snapshot create and restore support for projections #277
base: master
Are you sure you want to change the base?
Conversation
This is basically working, but the snapshot metadata is not persisted yet and thus one very concrete snapshot is currently hardcoded in ProjectionManager
Instructions:
|
Sorry for being the sceptic voice.. I probably over-react a little but I removed a lot of code from this package in order to keep it focused and scaleable so please bear with me and hear me out: In event sourcing snapshotting is usually applied to aggregates as performance optimization, i.e. in order to speed up reconstitution that is needed for every mutation.
Having said that I still think that it can be quite a useful tool but I wonder if the framework is a good place for the implementation. <?php
class SomeAggregateRepository {
public function load(SomeAggregateId $id): SomeAggregate
{
$snapshot = $this->loadSnapshot($id);
$eventStream = $this->eventStore->load($this->streamName($id), $snapshot->sequenceNumber());
return SomeAggregate::reconstituteFromSnapshotAndEventStream($snapshot, $eventStream);
}
public function save(SomeAggregate $aggregate): void
{
$this->eventStore->commit($this->streamName($id), $aggregate->pullUncommittedEvents(), $aggregate->getReconstitutionVersion());
if ($this->requiresSnapshot($aggregate)) {
$this->saveSnapshot($aggregate);
}
}
// ...
} We should add a proper example to the documentation and/or provide a base implementation, but IMO this could be done in a separate package because most of the code will be specific to the aggregate implementation. Now this PR is about snapshots for projections and – if I get it right – it serves a different scenario. A snapshot as described above doesn't make sense for projections IMO because the events are usually only applied once and the projection is only replayed if its implementation changed (which renders any previous snapshot invalid most probably). With #269 this should already be possible via
and this PR is "merely" there to speed up that process, right? |
Sorry if the above didn't sound constructive, I was mainly trying to turn my initial thoughts into writing. TL;DR: I'm not sure about the new interfaces and traits and would prefer a first implementation in the affected model. E.g. for the event-sourced Content Repository two new CLI commands
..at least until we learned more about it :) |
@bwaidelich that were exactly my thoughts when I saw the PR and thought about it :) |
@bwaidelich thanks for your comments. I guess it's mostly a misunderstanding. The motivation for this feature is mostly an optimization for debugging projections. It can be implemented as a separate package, if you like. It has nothing to do and does not aim for providing something like snapshots for aggregates. Consider having an event store full of 1.000.000 events and trying to debug / improve a specific projection. You'll end up in a replay - check database - catch up - adjust code - replay -loop. In my actual case a replay of the respective projection takes a few minutes. Now, if I could create a snapshot at event 990.000 and reset to / catch from there, this would be a big time-saver. If that is a too exotic feature, just let me know. @skurfuerst asked me to implement it for the ESCR development. |
|
This one got stuck after I shared my concerns. Now, almost one year later, I still think that "snapshots" should be avoided if possible (and apparently I'm not the only one, see https://twitter.com/mat_mcloughlin/status/1418191418309451780) and certainly don't be a part of the core functionality. Having said that, of course that's just my personal opinion and – more importantly – it doesn't mean that we should not make debugging large projections easier and faster! btw: I shared the twitter link above not to "prove my point" (and it doesn't for all cases) but it contains an interesting idea: How can we prevent (too) long living streams? |
createSnapshot()
andrestoreSnapshot()
Snapshot
objects so thatProjectionManager
and others can look up which snapshots (should) exist and retrieve metadataIdeas for later: