Event Sourcing: Code With the Flow

Does this sound familiar? At every turn you need better reporting and more information from your data but are unable to fill in the data gaps. Perhaps you have heard of DDD, CQRS, and event sourcing as possible solutions. Your interest is peaked, but it seems like your favorite framework is just not setup to give you the needed tooling. All the new names and concepts are confusing, and you are having a hard time keeping it all straight. It is like you are coding against the flow.


Don't worry, you are in good company. The answer might just be that you embrace the changing data and use an event store to code with the flow. At a recent Dallas PHP community meetup, I took the audience through a step-by-step build up of an event store built in a not-so-trivial Laravel application. Using the event store and the example code, you will have all you need to get started with event sourcing your data models.

Tap thumbnail to load video. Tap play icon once loaded to begin playing.

In the example application on Github, based on the automobile industry, you can manufacturer yourself a truck and register it with the DMV, storing all the changes as events along the way. Then you can read back the stream of events to recreate any moment-in-time representation of your truck. You can take snapshots of your event stream to optimize the event store, and re-insert events in time-sequence order. It is a playground to explore how event sourcing might be useful for your next application.

Good crowd for @dalabarge’s talk about event sourcing and events tonight!

@dallasphp (May 9, 2018)

You should walk away learning:

All the slides, code, and talking highlights are available: