Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Snapshot Store Laravel Package

prooph/snapshot-store

Lightweight snapshot store for prooph/event-sourcing setups. Provides a simple API to persist and load aggregate snapshots, reducing replay time and improving performance. Note: library support ended Dec 31, 2019 (deprecated).

View on GitHub
Deep Wiki
Context7

Product Decisions This Supports

  • Event Sourcing Optimization: Enables snapshot-based aggregate hydration to reduce event replay latency, critical for systems with high read volumes (e.g., financial transactions, real-time analytics dashboards). Directly addresses performance bottlenecks in event-sourced architectures.
  • Build vs. Buy: Buy—avoids reinventing snapshot storage logic (serialization, persistence, caching) while leveraging Prooph’s battle-tested ecosystem. Reduces technical debt compared to custom implementations.
  • Roadmap Priorities:
    • Phase 1: Integrate with existing event-sourcing infrastructure (e.g., prooph/event-sourcing) to enable snapshot-based aggregate loading for high-traffic aggregates (e.g., Order, UserProfile).
    • Phase 2: Implement multi-layer caching (e.g., Redis + PostgreSQL) via CompositeSnapshotStore to balance speed and durability, targeting 90%+ reduction in aggregate load times.
    • Phase 3: Deprecate full event replay for read-heavy aggregates, shifting to snapshot-based reconstruction to reduce database load by 50%.
  • Use Cases:
    • High-Throughput Systems: E-commerce order processing, SaaS multi-tenancy, or IoT telemetry aggregation where aggregate reconstruction is a bottleneck.
    • Audit-Heavy Domains: Healthcare records or legal document management where snapshots serve as compliance checkpoints and reduce event replay complexity.
    • Microservices: Decouple aggregate state from event storage to improve resilience and scalability in distributed systems.

When to Consider This Package

  • Adopt if:

    • Your system uses event sourcing (e.g., Prooph, EventSauce, or custom implementations) and aggregate loading is a performance bottleneck (e.g., >500ms latency).
    • You need lightweight, serializable snapshots with support for custom serializers (e.g., igbinary for performance or JSON for compatibility).
    • You require multi-layer caching (e.g., in-memory + persistent storage) via CompositeSnapshotStore to optimize for both speed and durability.
    • Your team is already using Prooph’s ecosystem (reduces integration risk and context-switching).
  • Look Elsewhere if:

    • You’re not using event sourcing: Snapshots are only useful in event-sourced architectures; alternatives like Laravel caching or database denormalization may suffice.
    • You need active development/maintenance: The package is deprecated (last update: 2021) with no clear successor. Evaluate alternatives like EventStoreDB or Axon Framework for long-term support.
    • Your snapshots require complex querying (e.g., time-travel queries, projections): This package focuses on fast hydration, not query flexibility.
    • You prefer managed services: Alternatives like EventStoreDB or Axon Server include built-in snapshot support with active maintenance.
    • Your PHP version is <7.2 or >8.0: Limited compatibility testing outside this range may introduce stability risks.

How to Pitch It (Stakeholders)

For Executives:

"This package allows us to eliminate a critical performance bottleneck in our event-sourced systems by storing snapshots—serialized states of our business objects—so we don’t have to replay thousands of events every time we need to read data. For example, in our order processing system, this would reduce database load during peak hours, improving response times for customer checkout by 30–50% while keeping our existing architecture intact. The trade-off is minimal: we’re adding a lightweight caching layer that’s already proven in production. Since the package is deprecated but stable, we’d treat it as a short-term optimization until we migrate to a long-term solution like EventStoreDB. The cost is low, and the ROI is immediate."

For Engineers:

*"Pros":

  • Performance Boost: Dramatically reduces aggregate loading time by avoiding full event stream replays (e.g., from 1s to <100ms for high-traffic aggregates).
  • Flexibility: Supports custom serializers (e.g., igbinary for speed, JSON for compatibility) and multi-layer storage (e.g., Redis + PostgreSQL) via CompositeSnapshotStore.
  • Prooph Integration: Plays nicely with Prooph’s event-sourcing stack (e.g., prooph/snapshotter). If you’re already using Prooph, this is a drop-in optimization with minimal setup.
  • Lightweight: ~100 LOC core, minimal dependencies, and no external service requirements.

Cons":

  • Deprecated: No new features, but stable for production use until we migrate. Monitor for critical bugs post-adoption.
  • Limited Querying: Snapshots are for fast loads, not complex queries (e.g., time-travel). Avoid using this for read models requiring historical snapshots.
  • PHP Version: Tested for 7.2–8.0; verify compatibility with your stack (e.g., Laravel 9+ may need adjustments).

Proposed Approach:

  1. Pilot: Integrate with a non-critical aggregate (e.g., UserProfile) to measure performance gains and validate the snapshot strategy.
  2. Expand: Roll out to high-traffic aggregates (e.g., Order, Inventory) with CompositeSnapshotStore (e.g., Redis for hot data + PostgreSQL for persistence).
  3. Monitor: Track snapshot hit ratios, database load reduction, and failure rates. Set alerts for snapshot corruption or missing data.
  4. Plan Exit: Evaluate long-term alternatives (e.g., EventStoreDB snapshots, Axon Framework) 12–18 months post-migration.

Alternatives Considered:

  • Roll Your Own: ~2–3 weeks of dev effort; higher risk of bugs/edge cases (e.g., serialization, concurrency).
  • EventStoreDB: All-in-one solution with built-in snapshots but requires architectural shift.
  • Axon Framework: Better long-term support but heavier integration and learning curve.

Recommendation: Proceed with caution. This is a short-term win for performance-critical aggregates, but we should budget for a replacement in 12–18 months to avoid dependency risks. Start with a proof-of-concept to validate gains before full rollout."*


For Developers:

*"Implementation Notes":

  • Setup: Requires prooph/event-sourcing and prooph/snapshotter. If not using Prooph, evaluate alternatives like Spatie’s EventSourcing.
  • Serialization: Defaults to PHP’s serialize() but supports custom strategies (e.g., igbinary for performance):
    $serializer = new CallbackSerializer('igbinary_serialize', 'igbinary_unserialize');
    $snapshotStore = new PdoSnapshotStore($pdo, ['snapshot_table' => 'aggregates'], $serializer);
    
  • Composite Stores: Combine caching (e.g., Redis) with persistence (e.g., PostgreSQL) for resilience:
    $cacheStore = new RedisSnapshotStore($redis);
    $persistenceStore = new PdoSnapshotStore($pdo);
    $compositeStore = new CompositeSnapshotStore([$cacheStore, $persistenceStore]);
    
  • Snapshot Strategy: Decide on snapshot frequency (e.g., per event, per transaction, or time-based) and retention policies (e.g., keep last 5 snapshots per aggregate).
  • Fallbacks: Ensure graceful degradation if snapshots are missing/corrupted (e.g., fall back to event replay):
    $repository = new PdoAggregateRepository($pdo, $metadata, $snapshotStore, $eventStore);
    
  • Testing: Validate edge cases (e.g., concurrent writes, large aggregate states) with load tests and chaos engineering (e.g., simulate snapshot failures).

Key Questions to Resolve:

  1. Which aggregates should prioritize snapshots? (Start with high-read, low-write domains.)
  2. What’s the snapshot serialization format? (igbinary for speed, JSON for compatibility?)
  3. How will we monitor snapshot health? (e.g., Prometheus metrics for hit ratios, failure rates)
  4. What’s the fallback strategy if snapshots are unavailable?"*
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
terminal42/code-quality-tools
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky