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

Event Sourcing Laravel Package

prooph/event-sourcing

Lightweight PHP event sourcing library with out-of-the-box integration for prooph/event-store. Provides an AggregateRoot base and AggregateTranslator, plus UUID generation and assertions support. Note: project was supported until Dec 31, 2019 and is deprecated.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Event Sourcing Alignment: Remains a native fit for Event Sourcing (ES) and CQRS architectures, particularly for:
    • Domain-Driven Design (DDD) implementations requiring immutable event logs.
    • Auditability & Temporal Queries (e.g., financial systems, supply chains).
    • Decoupled Microservices leveraging event-driven communication.
  • Laravel Compatibility: Still requires integration into domain layers, background jobs, or custom event stores, but now with PHP 8.1+ optimizations (e.g., named arguments, union types).
  • New PHP 8 Compatibility: Aligns with Laravel 9/10’s PHP 8.1+ baseline, reducing runtime compatibility friction and enabling:
    • Modern PHP features (e.g., array_unpack, match expressions) in aggregate logic.
    • Better type safety for event payloads and command handlers.

Integration Feasibility

  • Core Components:
    • Aggregate Roots: Can still map to Eloquent models or standalone classes, now with PHP 8.1+ performance benefits.
    • Event Stores: No changes to storage requirements (still needs Doctrine DBAL, Redis, or custom adapters).
    • Event Dispatching: Continues to integrate with Laravel’s event system or bus patterns (e.g., prooph/service-bus).
  • Challenges:
    • No Built-in ORM Integration: Still requires manual setup for event versioning/snapshotting.
    • Laravel’s Convention Over Configuration: May still need custom adapters for Laravel-specific workflows (e.g., migrations).
    • Testing Complexity: Temporal testing remains a challenge, but PHP 8.1’s attributes could simplify test doubles for aggregates.

Technical Risk

Risk Area Severity Mitigation Strategy
Storage Backend Dependency High Evaluate Doctrine DBAL or EventStoreDB compatibility; avoid vendor lock-in.
Performance Overhead Medium Benchmark event loading with PHP 8.1 JIT; consider snapshotting.
Laravel Ecosystem Gaps Medium Use Laravel’s service container to wrap aggregates; bridge with Lumen if needed.
Concurrency Issues High Implement optimistic locking (ExpectedVersion) or pessimistic locks.
Debugging Complexity High Log event streams; use Laravel’s debugbar for aggregate state.
PHP 8.1 Migration Risk Low Backward-compatible (no breaking changes in v5.7.0); test with Laravel 9/10.

Key Questions

  1. Storage Strategy:
    • Will we use Doctrine DBAL, Redis, or a dedicated event store (e.g., EventStoreDB)?
    • How will we handle event versioning and schema migrations in PHP 8.1?
  2. Aggregate Design:
    • Should aggregates leverage PHP 8.1 features (e.g., match expressions for event handling)?
    • How will we handle cross-aggregate transactions (e.g., sagas) with PHP 8.1’s concurrency model?
  3. Projection & Querying:
    • Will we use Laravel’s query builder for read models, or a separate projection service?
    • How will we ensure eventual consistency with PHP 8.1’s improved fiber support?
  4. Performance & Scaling:
    • What is the expected event throughput? Will PHP 8.1’s JIT improve event replay latency?
    • How will we handle large event streams (e.g., >1M events) with PHP 8.1’s memory model?
  5. Monitoring & Observability:
    • How will we track failed event processing (e.g., dead-letter queues) in PHP 8.1?
    • What metrics (e.g., event latency, replay time) will we monitor with PHP 8.1’s profiling tools?

Integration Approach

Stack Fit

  • Laravel Core:
    • Service Container: Register aggregates, event stores, and repositories as bindings (now with PHP 8.1’s constructor property promotion).
    • Queue System: Use laravel-queue for async event publishing (e.g., bus->dispatch()).
    • Middleware: Apply auth/validation middleware to command handlers (PHP 8.1’s attributes can simplify this).
  • Database Layer:
    • Doctrine DBAL: For SQL-based event storage (PHP 8.1’s typed arrays improve type safety).
    • Redis: For high-throughput event streams (with Laravel Redis package).
  • Event-Driven Extensions:
    • Prooph Service Bus: For command/event routing (PHP 8.1’s enums could model event types).
    • Laravel Echo/Pusher: For real-time event notifications (PHP 8.1’s fibers may aid async workflows).

Migration Path

Phase Action Items Tools/Libraries
Assessment Audit existing CRUD models for ES suitability; identify bounded contexts. DDD tools, Laravel Scout (for analysis)
Proof of Concept Implement 1-2 aggregates (e.g., Order, UserProfile) with event sourcing, using PHP 8.1 features. prooph/event-sourcing, Tinker for testing
Storage Integration Choose and configure event store (Doctrine DBAL/Redis/EventStoreDB). Doctrine DBAL, Predis, EventStore PHP client
Command Handling Replace Eloquent updates with command handlers (e.g., UpdateOrder), leveraging PHP 8.1 attributes. prooph/service-bus (optional)
Projection Layer Build read models (e.g., Laravel Eloquent or custom tables) with PHP 8.1 typed properties. Laravel Migrations, Query Builder
Testing Write event replay tests and aggregate state tests, using PHP 8.1’s attributes for test fixtures. PHPUnit, Laravel Pest
Deployment Gradually migrate write paths to ES; monitor performance & errors with PHP 8.1’s profiling tools. Laravel Forge/Envoyer, Sentry, Xdebug

Compatibility

  • Pros:
    • PHP 8.1+: Full compatibility with Laravel 9/10’s PHP 8.1+ features (e.g., named args, union types, attributes).
    • PSR Standards: Continues to follow PSR-15/PSR-14 where applicable.
    • Extensible: Can integrate with Laravel’s task scheduling (e.g., schedule:run) for projections.
  • Cons:
    • No Eloquent Integration: Still requires manual mapping between aggregates and DB.
    • No Built-in Caching: Must implement aggregate snapshotting for performance.
    • Laravel’s HTTP Focus: Not optimized for non-HTTP event sources (e.g., CLI jobs).

Sequencing

  1. Start with a Single Aggregate:
    • Example: Convert a User model to an event-sourced aggregate (UserAggregate) using PHP 8.1’s typed properties.
    • Publish events via Laravel commands or API controllers with PHP 8.1’s attributes for validation.
  2. Add Event Store:
    • Configure Doctrine DBAL or Redis for event persistence, leveraging PHP 8.1’s typed arrays for event payloads.
    • Implement event versioning (e.g., EventVersion field) with PHP 8.1’s enums.
  3. Implement Projections:
    • Create read-optimized tables (e.g., users_view) updated via Laravel jobs, using PHP 8.1’s fibers for async updates.
  4. Introduce Command Bus:
    • Replace direct model calls with command handlers (e.g., UpdateUserCommand) using PHP 8.1’s attributes for dependency injection.
  5. Scale Horizontally:
    • Add snapshotting for large aggregates with PHP 8.1’s serialization improvements.
    • Implement sharding if event volume grows, using PHP 8.1’s concurrency features.
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.
directorytree/privacy-filter-classifier
directorytree/privacy-filter
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
22h/doctrine-garbage-collection-bundle
agtp/agtp-php
agtp/mod-php
splash/sonata-admin
splash/metadata
splash/openapi
splash/scopes
splash/toolkit
testo/output-teamcity
testo/bridge-symfony
spatie/flare-daemon-runtime