Model::save()).bind() or tag().Order) and measure impact on read/write performance.$this->app->bind(SnapshotRepositoryInterface::class, function ($app) {
return new ProophSnapshotRepository(
$app->make(EventStoreInterface::class),
$app->make(SnapshotStorage::class) // Custom or Prooph's storage
);
});
public function getAggregate(string $aggregateId): AggregateRoot
{
$snapshot = $this->snapshotRepository->getSnapshot($aggregateId);
if ($snapshot) {
return $snapshot->rebuild();
}
return $this->eventStore->load($aggregateId);
}
SnapshotStorageInterface.SnapshotCreated events (if using Prooph).snapshot_at, version).php artisan snapshot:rebuild {aggregate-id} # Force rebuild from events
php artisan snapshot:validate {aggregate-id} # Verify snapshot consistency
lock() or database transactions).| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Stale snapshot (events appended post-snapshot) | Inconsistent reads | Use event count validation before snapshot use. |
| Corrupted snapshot (serialization error) | Aggregate rebuild fails | Fall back to event replay; log errors. |
| Snapshot storage outage | Reads fail if no fallback | Cache snapshots in Redis for resilience. |
| Concurrent snapshot updates | Data races | Use optimistic locking (e.g., version field). |
| Event store unavailable | Snapshots unusable | Implement local snapshot cache with TTL. |
How can I help you explore Laravel packages today?