Skip to content
Snippets Groups Projects

Event-Sourcing basic example app

Aim: learn basics of event-sourcing pattern and its caveats.

This project builds on example from presentation from Mathias Verraes - Practical Event Sourcing.

Learning matherial

Bellow is learning matherial that I've used to dive into event DDD (and its implementations) deeper.

DDD: Domain Driven Design

I've put DDD in it's own section because DDD is more analysis process then collection of structural patterns.

Case studies

Learning the Technical Stuff

This sections actually describes how people are implementing their domains discoved by using DDD. Be careful applying patters bellow blindly.

Event Sourcing + CQRS

Alternative implementation of domain model persistence layer which stores complete history of all events that happend to domain in past.

(The structural part of) DDD in PHP

Message Buses / libraries

Process Managers / Sagas (the same thing!)

Examples

Notes / TODOs

  • How to make proper relation between Product and Basket?
    • Answer: Analyse bounded contexts. (probably in most domains use two separate AggregateRoots)
  • How to access product name when product-related event occurs - aggregate does not expose any state?! (should I access read model from write model?)
    • Answer: Access read side if needed or use heavy events.
  • If aggregate produces event but it does not change state in any way, should it have empty apply() method for this event or should framework just skip this event. (this can lead into hard discoverable typo errors)
    • Answer: I would prefer to hot have this methods in aggregate and have some kind of static analysis check for method name and type consistency (in PHP which does not support method overloading).
  • Is there any point of adding events when loading from history into object "recoded events"?
    • Answer: No, if you load them there, they will be persisted once more / there will be need for merge proccess.