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
Laravel Event Sourcing

Laravel Event Sourcing Laravel Package

spatie/laravel-event-sourcing

Event sourcing toolkit for Laravel: build aggregates, projectors, and reactors to store state changes as events. Ideal for audit trails, decisions based on history, and future reporting needs. Includes docs, examples, and an optional course.

View on GitHub
Deep Wiki
Context7

The easiest way to get started with event sourcing in Laravel

Frequently asked questions about Laravel Event Sourcing
How do I get started with event sourcing in Laravel using this package?
Start by installing the package via Composer (`composer require spatie/laravel-event-sourcing`) and publishing its config. Follow the [official docs](https://spatie.be/docs/laravel-event-sourcing) to define your first aggregate, which encapsulates domain logic and emits events. Use the provided examples, like Larabank, to see real-world implementations.
What Laravel versions does this package support?
The package is officially tested on Laravel 9.x and 10.x. While it may work on older versions, some features like PHP 8.1+ type hints and attributes might require adjustments. Always check the [release notes](https://github.com/spatie/laravel-event-sourcing/releases) for compatibility details.
Can I use this package with PostgreSQL or other databases?
Yes, the package works with MySQL, PostgreSQL, and SQLite out of the box via Eloquent or raw queries. For PostgreSQL, you can leverage JSONB for efficient event storage. Custom adapters also allow integration with external stores like EventStoreDB or Redis for high-performance scenarios.
How do projectors and reactors differ, and when should I use each?
Projectors materialize read models by replaying events, ensuring your queries stay fast and consistent with the event store. Reactors trigger side effects (e.g., notifications, analytics) in response to events. Use projectors for reporting or UI data, and reactors for decoupled, event-driven actions like sending emails or updating caches.
Is this package suitable for high-traffic applications?
Event sourcing introduces performance tradeoffs: writes are atomic but may slow down under heavy load, while projections add latency for initial queries. Optimize with async processing (Laravel queues), batching, and caching. Monitor event store growth and consider distributed stores like EventStoreDB for scalability.
How do I handle testing with event sourcing in Laravel?
Test aggregates by replaying events to reconstruct state, then assert behavior. Use the package’s `EventSourcingTestCase` for helper methods. For projections, test by replaying events and verifying materialized data. Seed test data by replaying historical events or using fixtures. Debugging tools like Spatie’s Event Sourcing Debugger can help visualize event flows.
Can I migrate an existing Laravel app to event sourcing incrementally?
Yes, adopt event sourcing gradually. Start with a single aggregate (e.g., `Order`) and emit events alongside existing CRUD operations. Use reactors to bridge events to legacy services. Later, replace CRUD with event-driven logic and introduce projections for queries. The package supports hybrid approaches to minimize disruption.
What are the alternatives to this package for event sourcing in Laravel?
For Laravel, alternatives include custom implementations using Doctrine Event Sourcing or libraries like `prooph/event-store`. For broader PHP support, consider `spiral/event-sourcing` or `codeland/event-sourcing`. However, this package stands out for its Laravel-native integration, comprehensive docs, and real-world examples like Larabank.
How do I handle event store backups or disaster recovery?
The event store is your single source of truth, so back it up like any critical database. Use database backups or tools like `pg_dump` for PostgreSQL. For distributed systems, consider replication or external stores with built-in durability (e.g., EventStoreDB). Always test restore procedures by replaying events from backups.
Does this package support event versioning or schema migration?
The package doesn’t include built-in schema migration for events, but you can version events by including a `version` field in your event payloads. Handle backward compatibility by writing reactors or projectors that ignore unknown event fields. For database schema changes, use Laravel migrations to alter the event store tables (e.g., adding columns).
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.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport