Event Sourcing

Post on 26-Jun-2015

338 views 2 download

Tags:

description

Presentation November 13, 2014 at 010PHP, Rotterdam, http://www.meetup.com/010PHP/events/212147112/ about Event Sourcing: In many applications the current state is constantly updated, overwriting previous states. Information about the history is lost then. With Event Sourcing you store all events that have led to a change in application state. The current and previous states can always be reconstituted from the series of events that has been stored. That gives lots of possibilities. I gave an overview of the background of Event Sourcing, with a sidestep to some thoughts about 'identity'. Related concepts, like CQRS and other DDD-jargon, were explained and I briefly mentioned Functional Programming. After my talk we looked at Broadway, the open sourced project from Qandidate, that provides a PHP infrastructure for Event Sourcing and CQRS. FritsJan Bakker, one of the builders of Broadway, told something more about it and how they used Event Sourcing at Qandidate. ----- Summary of slides: * 2-3: while updating, history is lost * 4: an n:m relationship where info of the past was stored * 5-7: DDD-jargon: Aggregate and Aggregate Root * 8-10: Demeter's Law as applied to the Aggregate Root * 11-17: Event Sourcing, storing past events, like in accounting * 18-25: about identity (you are the realisation of changes) * 26: Functional Programming (same paradigm as ES) * 27-30: CQRS and the bigger picture * 31-33: Broadway * 34: Pool Request

Transcript of Event Sourcing

Herman Peeren010PHP

November 2014

Event Sourcing

Update

Update

Entities - Relationships

DDD-jargon: Aggregate

Aggregate: house of cooperating entities (consistency boundaries)

DDD-jargon: Aggregate Root

Aggregate root: the entrance of the house, the interface to the outside world

DDD-jargon: Aggregate Root

Aggregate protects its own invariants: keep your house clean

Demeter’s Lawonly talk to your immediate friends

Demeter’s LawCommand the dog, not the dog’s legs

Demeter’s LawCommand the dog, not the dog’s legs

Event Sourcing• you don’t store the state, • but the proces that caused the change

Accounting: same principle• you don’t store the changed balance, • but the journal entries that caused the change

Event Sourcing• you don’t add an item to a collection of jobs, • but you take or quit a job

Event Sourcing• you don’t add an item to a collection of jobs, • but you hire or fire someone

Emphasis on the action, using words used in the domain, not on the data

Event Store

Event Store

Event Sourcing

EntityEquality is decided by its identity, not by its values

never too old to run

Theseus’ship paradox

Theseus’ship paradox

Theseus’ship paradox

Identity

Identity

Identity

IdentityYou are who you were + the difference since then

Functional ProgrammingData are what they were + the difference since then

Event Sourcing & CQRSCQRS = Command Query Responsibility Segregation: separate Read & Write Model

Event Sourcing & CQRS

FromtheAxonFrameworkdocumentation

Event Sourcing & CQRS

Event Sourcing+• lossles, extra read-models can always later be added• more verbs than data centric, closer to mental model and domain language

-• increased complexity when state is rarely updated

CQRS+• loosely coupled, specialised read & write side• scalability

-• more complexity when project is not complex or doesn’t need scaling

Broadway

Broadway: namespaces

Broadway: examples

Other interesting PHP framework (less production-ready?): https://github.com/szjani/predaddy

Pool RequestJoomlaWorldConference,Mexiconovember2014

Thank you!

herman@yepr.nl

hermanpeeren.nl@HermanPeeren

November 13, 2014

Credits:Sorry! For this presentation I’ve used all kinds of images I collected from the web during the past months. I didn’t note down the various sources, so I cannot give credit to the owners of the images. I can only thank you all very much for making them available on the internet and I hope I did not violate your rights too much borrowing them. If you own the rights to an image used here, please let me know and I will mention it (or take the image out of these slides if you want to).