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

Eventsauce Outbox Laravel Package

andreo/eventsauce-outbox

Extended outbox components for EventSauce on PHP 8.2+. Includes an outbox-aware aggregate repository, a forwarding message consumer to dispatch to your queue, and a Symfony Console command to consume relays with batch/commit, sleep, and limit options.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Event-Driven Architecture (EDA) Synergy: The package leverages the outbox pattern, a critical component for reliable event publishing in distributed systems. It aligns seamlessly with Laravel-based event-sourced architectures, CQRS, or microservices where eventual consistency is required.
  • Decoupling and Scalability: By separating event storage (EventSauce) from message dispatching (queues/APIs), the package enables horizontal scaling and asynchronous processing, reducing coupling between services.
  • Laravel Adaptability: While the package is Symfony-centric, its core outbox logic is framework-agnostic. A TPM can abstract Symfony dependencies (e.g., ServiceLocator, Console) to integrate it into Laravel using:
    • Symfony Bridge (e.g., symfony/console via Composer).
    • Custom Laravel wrappers (e.g., replacing ServiceLocator with Illuminate\Container).
    • Artisan command replacements for Symfony CLI tools.
  • Transaction Management: The outbox pattern relies on database transactions to ensure atomicity. Laravel’s transaction system must be synchronized with EventSauce’s to avoid inconsistent state or message loss.

Integration Feasibility

  • EventSauce Dependency: The package extends EventSauce, so adoption assumes EventSauce is already in use or planned. If not, migrating from Laravel’s Eloquent to EventSauce requires:
    • Schema changes (event tables, projections).
    • Aggregate root refactoring (from models to event-sourced entities).
    • Team upskilling on CQRS/ES patterns.
  • Queue System Compatibility: The package assumes a queue system (e.g., RabbitMQ, Kafka) for message dispatch. Laravel’s queue drivers (Redis, database) can be used, but:
    • Serialization/deserialization may require custom logic for EventSauce’s message format.
    • Batch processing (via batch-size/commit-size) must align with Laravel’s queue worker capabilities.
  • Database Schema: The outbox pattern typically requires an outbox_messages table. EventSauce may handle this, but a TPM must:
    • Verify schema compatibility with Laravel’s migrations.
    • Ensure transactions span both EventSauce and Laravel’s database layers.

Technical Risk

  • Symfony Framework Lock-In: Heavy reliance on Symfony components (e.g., ServiceLocator, Console) introduces:
    • Abstraction overhead if not properly wrapped.
    • Maintenance complexity if Symfony versions diverge from Laravel’s ecosystem.
  • Transaction Boundaries: Misalignment between Laravel’s transactions and EventSauce’s can lead to:
    • Message loss (if events are committed but not dispatched).
    • Inconsistent state (if dispatches fail after event commit).
  • Queue System Assumptions: If Laravel’s queue drivers lack support for:
    • Batch processing, performance may degrade.
    • EventSauce’s message format, serialization/deserialization may fail.
  • Observability Gaps: The package lacks built-in metrics for:
    • Outbox lag (unpublished events).
    • Failure rates (e.g., poison messages).
    • A TPM must implement custom logging/monitoring (e.g., Laravel’s Log facade or Prometheus).

Key Questions

  1. EventSauce Adoption:
    • Is EventSauce already in use, or is this a greenfield project? If greenfield, assess the cost of migrating from Eloquent to event sourcing.
  2. Queue System:
    • Which Laravel queue driver is in use? Does it support batch processing and EventSauce’s message format?
  3. Transaction Strategy:
    • How will distributed transactions be managed between Laravel and EventSauce? Will a Saga pattern or compensating transactions be needed?
  4. Failure Recovery:
    • How will failed dispatches (e.g., poison messages) be handled? Does the package support dead-letter queues?
  5. Performance:
    • What are the throughput requirements for event publishing? The batch-size and commit-size settings may need tuning.
  6. Monitoring:
    • How will outbox lag and dispatch failures be monitored? Are there plans to integrate with Laravel’s Horizon or third-party tools?
  7. Team Expertise:
    • Does the team have experience with EventSauce, outbox patterns, or Symfony integration in Laravel? If not, budget for training or hiring.

Integration Approach

Stack Fit

  • Core Components:
    • EventSauce: Must replace or coexist with Laravel’s Eloquent for event-sourced aggregates. Requires:
      • Event tables (e.g., events).
      • Projections (read models) if CQRS is used.
    • Laravel Queue System: Can be the target for dispatched messages, but requires:
      • A custom adapter to bridge EventSauce’s MessageDispatcher with Laravel’s Bus or Queue system.
      • Serialization logic if EventSauce’s message format differs from Laravel’s queue payloads.
    • Database: Must support transactions and schema for outbox messages. Laravel’s migrations can extend EventSauce’s tables.
  • Symfony Dependencies:
    • ServiceLocator: Replace with Laravel’s container or a custom service locator (e.g., Illuminate\Support\ServiceLocator).
    • Console Component: Rewrite the OutboxMessagesConsumeCommand as a Laravel Artisan command or use a Symfony Bridge (e.g., symfony/console via Composer).
  • Alternatives:
    • If Symfony integration is prohibitive, consider native Laravel outbox packages (e.g., spatie/laravel-outbox) and adapt EventSauce’s logic to work with them.

Migration Path

  1. Phase 1: Adopt EventSauce
    • Replace Laravel’s ORM with EventSauce for event-sourced aggregates.
    • Set up projections (read models) if CQRS is required.
    • Configure EventSauce’s message repository and dispatcher.
  2. Phase 2: Integrate Outbox Pattern
    • Implement the EventSourcedAggregateRootRepositoryForOutbox with Laravel-compatible dependencies:
      • Replace ServiceLocator with Laravel’s container.
      • Adapt MessageRepository and AggregateRootRepository to work with Laravel’s database.
  3. Phase 3: Bridge Message Dispatching
    • Develop a custom adapter to forward EventSauce messages to Laravel’s queue:
      • Extend EventSauce\EventSourcing\MessageDispatcher to use Laravel’s Bus or Queue system.
      • Handle serialization/deserialization if needed.
  4. Phase 4: Replace Symfony CLI
    • Convert OutboxMessagesConsumeCommand to an Artisan command:
      • Use Laravel’s Artisan::command() to replicate Symfony’s CLI functionality.
      • Integrate with Laravel’s scheduling (e.g., Schedule::command()) for automated processing.
  5. Phase 5: Testing and Optimization
    • Test transaction boundaries between Laravel and EventSauce:
      • Ensure events are committed before dispatch.
      • Verify rollbacks work correctly on failure.
    • Optimize batch-size and commit-size based on performance metrics (e.g., TPS, latency).

Compatibility

  • Laravel Version: Ensure compatibility with PHP 8.2+ (Laravel 10+).
  • EventSauce Version: Verify the package works with the latest EventSauce (or a supported version).
  • Queue Drivers: Test with Laravel’s supported queue drivers (Redis, database, etc.) to ensure:
    • Serialization of EventSauce messages.
    • Batch processing aligns with worker capabilities.
  • Database: Confirm the outbox table schema aligns with Laravel’s migration system and supports:
    • Transactions spanning EventSauce and Laravel.
    • Indexing for performance (e.g., relay_id, processed_at).

Sequencing

  1. Set Up EventSauce:
    • Configure EventSauce as the event store and message dispatcher.
    • Define aggregates and events in Laravel-compatible classes.
  2. Implement Outbox Repository:
    • Create a Laravel-compatible EventSourcedAggregateRootRepositoryForOutbox:
      • Inject Laravel’s container instead of Symfony’s ServiceLocator.
      • Use Laravel’s database connection for MessageRepository.
  3. Bridge Message Dispatching:
    • Develop a custom MessageDispatcher adapter:
      • Extend EventSauce\EventSourcing\MessageDispatcher to push messages to Laravel’s queue.
      • Handle payload serialization (e.g., JSON, MessagePack).
  4. Replace Console Command:
    • Rewrite OutboxMessagesConsumeCommand as an Artisan command:
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.
daikazu/eloquent-salesforce-objects
unseen-codes/chat
romalytar/yammi-jobs-monitoring-laravel
kisame76/filament-db-table-state
nqxcode/laravel-lucene-search
dpfx/laravel-livewire-wizards
workos/workos-php-laravel
sofa/laravel-global-scope
nawasara/auth-primitives
adhocrat-io/arkhe-main
make-dev/orca-harpoon
itsemon245/lamet
baks-dev/dashboard
amoifr/pickle-panther-bundle
make-dev/orca
dmstr/symfony-system-resources-bundle
dmstr/symfony-job-queue-bundle
dmstr/openapi-json-schema-bundle
dmstr/keycloak-security-bundle
dmstr/doctrine-audit-log-bundle