Event Sourcing
Event Sourcing in PHP — built-in event store, partitioned and streaming projections, gap detection, projection emission, and end-to-end PII encryption on Laravel and Symfony
The Problem You Recognize
What the Industry Calls It
How Ecotone Solves It
Event-sourced aggregates as plain PHP
#[EventSourcingAggregate]
final class Order
{
use WithAggregateVersioning;
#[Identifier] private string $orderId;
private OrderStatus $status = OrderStatus::Placed;
private int $amount = 0;
#[CommandHandler]
public static function place(PlaceOrder $command): array
{
return [new OrderWasPlaced($command->orderId, $command->amount)];
}
#[EventSourcingHandler]
public function whenPlaced(OrderWasPlaced $event): void
{
$this->orderId = $event->orderId;
$this->amount = $event->amount;
}
#[CommandHandler]
public function pay(PayOrder $command): array
{
if ($this->status !== OrderStatus::Placed) {
return [];
}
return [new OrderWasPaid($this->orderId, $command->paymentId)];
}
#[EventSourcingHandler]
public function whenPaid(OrderWasPaid $event): void
{
$this->status = OrderStatus::Paid;
}
}Projections that scale, with gap detection and emission
End-to-end PII encryption
Blue-green rebuilds, async backfill, streaming projections
How It Compares
Dimension
Spatie laravel-event-sourcing
EventSauce
Patchlevel event-sourcing
Ecotone
Next Steps
Last updated
Was this helpful?