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

Php Event Store Laravel Package

event-engine/php-event-store

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Event-Driven Alignment: The package enforces event sourcing and CQRS principles, which are critical for auditability, replayability, and scalability in Laravel applications (e.g., financial systems, user activity tracking). Its contract-based design ensures consistency across microservices or monolithic Laravel apps.
  • Laravel Synergy: While Laravel lacks native event store support, this package can integrate with Laravel’s event system, queue system, or Eloquent for persistence. The AggregateRoot pattern aligns with Laravel’s service layer and repository pattern.
  • Flexibility: The contract allows swapping storage backends (e.g., PostgreSQL → Kafka) without changing business logic, reducing vendor lock-in. This is valuable for Laravel apps with evolving infrastructure needs.

Integration Feasibility

  • Low-Coupling Design: The package’s interface-only approach enables seamless integration with Laravel’s dependency injection and service container. For example:
    • Bind the EventStore interface to a custom Laravel implementation in AppServiceProvider.
    • Use Laravel’s queue system to asynchronously append events.
  • PHP Compatibility: Supports PHP 8+, aligning with Laravel’s LTS versions (8.x–10.x). Recent fixes (e.g., PHP 8.4 deprecations) indicate active maintenance.
  • Tooling Support: Includes PHPUnit and security advisories, ensuring compatibility with Laravel’s testing and security practices.

Technical Risk

  • No Built-in Persistence: The package requires a custom implementation for storage (e.g., database, file system). Risks include:
    • Performance overhead if events are stored in Laravel’s default database without optimization (e.g., indexing, partitioning).
    • Schema management for event versioning (e.g., handling backward/forward compatibility).
  • Laravel-Specific Challenges:
    • Eloquent Conflicts: If using Eloquent for event storage, conflicts may arise with Laravel’s migrations, model events, or relationships.
    • Queue Integration: Async event processing (via Laravel’s queue) requires custom logic for retry mechanisms and dead-letter queues.
  • Testing Complexity: Event replay and aggregate reconstruction must be tested rigorously, which may require custom Laravel test helpers or mock event stores.

Key Questions

  1. Storage Strategy:
    • Will events be stored in Laravel’s default database, a dedicated schema, or an external system (e.g., Kafka, Redis)?
    • How will event versioning and schema migrations be handled?
  2. Laravel Integration:
    • Should events trigger Laravel’s bus or events system? How will this interact with the event store?
    • How will aggregate loading be optimized (e.g., caching, snapshots) in Laravel’s context?
  3. Concurrency and Fault Tolerance:
    • How will optimistic locking or conflict resolution be implemented (e.g., via Laravel’s lock() or a custom solution)?
    • What retry mechanisms will be used for failed event processing (e.g., queue retries, dead-letter queues)?
  4. Performance:
    • How will event loading/replay be optimized for large aggregates (e.g., snapshots, pagination)?
    • What monitoring will be added for event store health (e.g., Laravel Horizon for queue metrics)?
  5. Team Readiness:
    • Does the team have experience with event sourcing and DDD? If not, what training or documentation is needed?
    • How will event-driven design be enforced in Laravel’s MVC layers (e.g., controllers, services)?

Integration Approach

Stack Fit

  • Laravel Event System: The package can integrate with Laravel’s Illuminate\Events or Illuminate\Bus to emit/store events. For example:
    • Use EventStore::append() in Laravel’s EventServiceProvider to persist events.
    • Dispatch events via Bus::dispatch() for async processing.
  • Queue Integration: Events can be published to Laravel’s queue for asynchronous processing, leveraging ShouldQueue interfaces or manual queue jobs.
  • Third-Party Libraries:
    • Spatie Event Sourcing: Can complement this contract for storage (e.g., using Spatie’s PostgreSQL event store).
    • Prooph Event Store: If using Prooph’s CQRS bundle, this contract could standardize interfaces across the stack.

Migration Path

  1. Phase 1: Contract Adoption

    • Define Laravel-specific implementations of EventStore and AggregateRoot.
    • Example:
      class LaravelEventStore implements EventEngine\EventStore\EventStore {
          public function loadAggregate(string $aggregateId): AggregateRoot {
              return AggregateRoot::fromEvents($this->fetchEvents($aggregateId));
          }
          public function save(AggregateRoot $aggregate): void {
              $this->persistEvents($aggregate->getEvents());
          }
      }
      
    • Register the store in Laravel’s service container (AppServiceProvider).
  2. Phase 2: Storage Layer

    • Implement storage using Laravel’s migrations and Eloquent models:
      Schema::create('events', function (Blueprint $table) {
          $table->id();
          $table->string('aggregate_id');
          $table->string('event_name');
          $table->json('data');
          $table->integer('version');
          $table->timestamps();
      });
      
    • Create a repository to handle CRUD operations for events.
  3. Phase 3: Integration

    • Replace direct Eloquent saves with event store calls in services or commands.
    • Use Laravel’s bus for async event publishing (e.g., Bus::dispatch(new CreateUserEvent(...))).
    • Extend Laravel’s EventServiceProvider to listen to domain events and persist them via the event store.
  4. Phase 4: Testing and Optimization

    • Write unit tests for aggregate reconstruction and event replay.
    • Add snapshots or caching (e.g., Redis) for performance-critical aggregates.
    • Implement monitoring (e.g., Laravel Horizon for queue metrics).

Compatibility

  • Laravel 8+: Fully compatible (PHP 8.x support, active maintenance).
  • Laravel 7: Possible with PHP 7.4, but lacks PHP 8 features (e.g., union types, attributes).
  • Existing Codebase:
    • Low Risk: If using dependency injection and service-oriented design.
    • High Risk: If tightly coupled to Eloquent or non-event-driven patterns (e.g., direct model saves).

Sequencing

  1. Define Domain Models: Model aggregates and events using DDD principles (e.g., UserAggregate, UserCreatedEvent).
  2. Implement Event Store: Create a Laravel-compatible EventStore class with storage logic.
  3. Integrate with Laravel:
    • Bind the event store to Laravel’s service container.
    • Replace direct model saves with event store calls in services or commands.
  4. Test Event Replay: Verify aggregate reconstruction works end-to-end.
  5. Optimize: Add snapshots, caching, or async processing for scalability.
  6. Monitor and Iterate: Add logging, metrics, and alerts for event store health.

Operational Impact

Maintenance

  • Pros:
    • Decoupled Design: Reduces tight coupling to Laravel’s internals, making it easier to swap storage backends.
    • MIT License: Allows customization without legal constraints.
    • Active Maintenance: Recent PHP 8.4 fixes and security advisories indicate ongoing support.
  • Cons:
    • No Built-in Tooling: Requires custom solutions for event management (e.g., replay, cleanup).
    • Manual Handling: Event versioning, schema changes, and conflict resolution must be managed manually.

Support

  • Learning Curve:
    • Team must understand event sourcing, DDD, and aggregate patterns, which may require training.
    • Laravel developers may need to unlearn ORM-centric habits (e.g., direct model saves).
  • Debugging:
    • Event Replay Debugging: Complexity arises from tracing aggregate state changes across events.
    • Lack of Built-in Tools: May need custom Artisan commands (e.g., php artisan event:replay) or Tinker helpers for diagnostics.
  • Documentation Gaps:
    • Limited Laravel-specific examples; may need to create internal docs or workshops.

Scaling

  • Performance:
    • Event Loading: Without snapshots, loading large aggregates may be slow. Consider pagination or projection tables.
    • Concurrency: Optimistic locking or Laravel’s lock() must be implemented to handle race conditions.
    • Storage Growth: Event tables may grow large; consider partitioning (e.g., by aggregate type) or archiving old events.
  • Read Models (CQRS):
    • Requires event listeners or queue jobs to update read models (e.g., Elasticsearch
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