Event Sourcing in PHP for Beginners

Easy tutorial for beginner PHP developers. Do you want to start with Event Sourcing in PHP? Let me show you.

.com software
4 min readOct 9, 2022
Image by Cottonbro

WARNING about the publication: it is a Work-In-Progress. It is going to be updated periodically with major changes.

Have you always wanted to start Event Sourcing but did not know how to get started? This publication is just for you.

We will go through a short description of what this technique is about; where and when to use it; we will finish with an example application in Symfony! Are you interested? Then let’s start the journey!

CRUD and Event Sourcing differences

As a rule, we are used to the traditional model of storing the state of objects in database tables. Each row is mapped to an object using an Object-Relational-Mapper (ORM) framework (think Eloquent, Doctrine, Propel).

In the traditional model, the database table always holds the last state of the object. In the case of Event Sourcing, we store events that occurred upon that object instead.

Bank account example

The simplest example is handling a bank account. Bob deposited $100 one day, then spent $70 on groceries, then $10 more…

--

--

.com software

Father • PHP developer • entrepreneur • working for a €1bn unicorn startup as a backend engineer >>> https://bit.ly/dotcom-software