🔧 AI Nachrichten Major AI platforms go down in unprecedented simultaneous outage(03.09.2026 um 17:34 Uhr)
🔧 AI Nachrichten ChatGPT, Claude, and Grok Down? Users Report Widespread Outages(03.09.2026 um 19:14 Uhr)
🔧 AI Nachrichten OpenAI Launches GPT-6 Astra, Says We May Have Entered the AGI Era(03.09.2026 um 22:08 Uhr)
🔧 AI Nachrichten Claude Comes to CarPlay as Fifth Major AI Chatbot App(05.09.2026 um 05:31 Uhr)
🔧 AI Nachrichten OpenAI’s GPT-6 Astra Is AGI, Says NVIDIA CEO Jensen Huang(07.09.2026 um 06:31 Uhr)
🔧 AI Nachrichten Blame AI companies for Mac mini and Mac Studio shortage(31.08.2026 um 10:32 Uhr)
🔧 AI Nachrichten Major AI platforms go down in unprecedented simultaneous outage(03.09.2026 um 17:34 Uhr)
🔧 AI Nachrichten ChatGPT, Claude, and Grok Down? Users Report Widespread Outages(03.09.2026 um 19:14 Uhr)
🔧 AI Nachrichten OpenAI Launches GPT-6 Astra, Says We May Have Entered the AGI Era(03.09.2026 um 22:08 Uhr)
🔧 AI Nachrichten Claude Comes to CarPlay as Fifth Major AI Chatbot App(05.09.2026 um 05:31 Uhr)
🔧 AI Nachrichten OpenAI’s GPT-6 Astra Is AGI, Says NVIDIA CEO Jensen Huang(07.09.2026 um 06:31 Uhr)
🔧 AI Nachrichten Blame AI companies for Mac mini and Mac Studio shortage(31.08.2026 um 10:32 Uhr)

🔧 Programmierung 🕛 kürzlich 2 Min Lesezeit
0

Stop Overwriting Your Data: Event Sourcing in Laravel 🕰️

↗ Quelle (dev.to)
🗣️ Stimme:
📑 Inhaltsübersicht

The Problem with Traditional State



Most Laravel applications rely on standard CRUD (Create, Read, Update, Delete) architecture. When a user changes their account balance, the old balance in the database is overwritten. But what if you need to know why the balance changed? What if you need to audit the system to find a bug introduced three months ago?



Traditional databases only store current state. They suffer from data amnesia. At Smart Tech Devs, when we build financial ledgers, audit-heavy platforms, or complex enterprise systems, we abandon state-based storage and implement Event Sourcing.



What is Event Sourcing?



Instead of storing the current state of a model, Event Sourcing stores every change that has ever occurred to that model as an immutable sequence of events. The current state is simply calculated by playing all those events from the beginning of time.



Step 1: Storing the Events



Instead of an accounts table with a balance column, we have an events table. When money is deposited, we don't update a balance; we record a MoneyDeposited event.



CODE

// ❌ Traditional CRUD Pattern
$account = Account::find(1);
$account->balance += 500;
$account->save();

// ✅ Event Sourced Pattern
$accountAggregate = AccountAggregateRoot::retrieve($uuid);
$accountAggregate->depositMoney(500, 'Salary deposit')
->persist();


Step 2: Projections (The Read Model)



Calculating the balance on the fly by reading thousands of events would be too slow for an API response. This is where Projections come in. A projector listens for events as they happen and updates a fast, read-optimized database table.



CODE

namespace App\Projectors;

use App\Events\MoneyDeposited;
use App\Models\AccountProjection;
use Spatie\EventSourcing\EventHandlers\Projectors\Projector;

class AccountBalanceProjector extends Projector
{
public function onMoneyDeposited(MoneyDeposited $event)
{
// This table is purely for fast reading.
// The source of truth remains the events table.
$account = AccountProjection::firstOrCreate(['uuid' => $event->aggregateRootUuid()]);
$account->balance += $event->amount;
$account->save();
}
}


The Engineering ROI



If your projection table gets corrupted, you simply delete it and replay your events to rebuild it perfectly. You gain a 100% accurate audit log, the ability to time-travel your application state to any point in the past, and decoupled read/write architectures (CQRS). It introduces complexity, but for the right domain, it is a superpower.

Vollständiger Original-Bericht
Ausführliche Details, Code-Beispiele & Hersteller-Stellungnahme auf dev.to.
↗ Original-Artikel auf dev.to lesen
Wie bewertest du diesen Beitrag?
1 Klick Feedback
Teilen mit Netzwerk & Team:

Community-Analysen & Experten-Meinungen 0

Verfasse deine eigene Analyse, teile Workarounds oder diskutiere diesen Vorfall im Blog.
Noch keine Community-Analyse verfasst. Markiere einen Textabschnitt oder klicke oben auf Eigene Analyse verfassen“!
Community Pulse: Relevanz-Einschätzung
1 Klick Experten-Votum
🔴 Akute Relevanz 0%
🟡 In Evaluierung 0%
🟢 Keine Auswirkung 0%
Spannende Innovation 0%
Verwandte Story-Cluster & Quellen (Vektor-KI)
Port 8095 Engine
3 Quellen
GPT-6 Astra Release Today? OpenAI’s Next Major AI Model Is Almost Here
1 Quelle
Apple accuses OpenAI of destroying evidence as trade-secrets fight intensifies
1 Quelle
Major AI platforms go down in unprecedented simultaneous outage
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Stop Overwriting Your Data: Event Sourcing in Laravel 🕰️

Thematisch verwandte Begriffe: Stop, Overwriting, Your, Data · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...