CQRS and Event Sourcing
with PHP
Who am I?
@marcelsud
Before we start
● Who knows what CQRS is?
● Who did already use CQRS in production?
● Who knows what Event Sourcing is?
● Who did already use Event Sourcing in production?
What CQRS is not?
● CQRS is not an architecture
● CQRS is not eventual consistency
● CQRS is not messaging
● CQRS is not eventing
● CQRS is not event sourcing
● CQRS is not CQS
● CQRS is not new
● CQRS is not hard to implement
● CQRS is not having separated models for reading and writing **
What is CQRS?
● Command and Query Responsibility Segregation
● It is essentially the creation of two objects
where there was previously only one **
Before
After
Or...
● Implement Event Sourcing
CQRS makes it easier to...
● Implement task based UIs
● Scale the read and write models independently
● Have multiple read models (which helps
reducing coupling)
● Tactician
Some libraries for CQRS
● SimpleBus
● Broadway
● Prooph
● Symfony Messenger
● State is built from the events
● No state is stored, only events
But what about Event Sourcing?
But what about Event Sourcing?
Picture from: https://www.confluent.io
Event Sourcing benefits
● It is possible to create data-views specialized for
certain cases
● It enables a 100% reliable audit log of the
changes made to a business entity
● It decouples the representation of current state in the
domain from the storage
● It facilitates the migration from monolithic
applications into smaller pieces
● It enables temporal queries that determine the state of
an entity at any point in time
Event Sourcing drawbacks
● It is a different and unfamiliar style of programming
and so there is a learning curve
● You’ll also probably have to introduce a little
more infrastructure to get up and running
● Not so simple onboarding of new team members
● Handling schema changes is not so simple as
the events are immutable
● To handle entities with long and complex
lifespans requires some “snapshot” strategy
What about Projections?
Picture from: https://goo.gl/btBWH1
Some libraries for Event Sourcing
● Broadway
● Prooph
● EventSauce
Any questions?
Thanks!
@marcelsud

CQRS and Event Sourcing with PHP

  • 1.
    CQRS and EventSourcing with PHP
  • 2.
  • 3.
    Before we start ●Who knows what CQRS is? ● Who did already use CQRS in production? ● Who knows what Event Sourcing is? ● Who did already use Event Sourcing in production?
  • 4.
    What CQRS isnot? ● CQRS is not an architecture ● CQRS is not eventual consistency ● CQRS is not messaging ● CQRS is not eventing ● CQRS is not event sourcing ● CQRS is not CQS ● CQRS is not new ● CQRS is not hard to implement ● CQRS is not having separated models for reading and writing **
  • 5.
    What is CQRS? ●Command and Query Responsibility Segregation ● It is essentially the creation of two objects where there was previously only one **
  • 6.
  • 7.
  • 8.
  • 9.
    ● Implement EventSourcing CQRS makes it easier to... ● Implement task based UIs ● Scale the read and write models independently ● Have multiple read models (which helps reducing coupling)
  • 10.
    ● Tactician Some librariesfor CQRS ● SimpleBus ● Broadway ● Prooph ● Symfony Messenger
  • 11.
    ● State isbuilt from the events ● No state is stored, only events But what about Event Sourcing?
  • 12.
    But what aboutEvent Sourcing? Picture from: https://www.confluent.io
  • 13.
    Event Sourcing benefits ●It is possible to create data-views specialized for certain cases ● It enables a 100% reliable audit log of the changes made to a business entity ● It decouples the representation of current state in the domain from the storage ● It facilitates the migration from monolithic applications into smaller pieces ● It enables temporal queries that determine the state of an entity at any point in time
  • 14.
    Event Sourcing drawbacks ●It is a different and unfamiliar style of programming and so there is a learning curve ● You’ll also probably have to introduce a little more infrastructure to get up and running ● Not so simple onboarding of new team members ● Handling schema changes is not so simple as the events are immutable ● To handle entities with long and complex lifespans requires some “snapshot” strategy
  • 23.
    What about Projections? Picturefrom: https://goo.gl/btBWH1
  • 26.
    Some libraries forEvent Sourcing ● Broadway ● Prooph ● EventSauce
  • 27.
  • 28.