Slide 1

Slide 1 text

CQRS Event Sourcing in OLX

Slide 2

Slide 2 text

CQRS

Slide 3

Slide 3 text

you can use a different model to update information than the model you use to read information http://martinfowler.com/bliki/CQRS.html „

Slide 4

Slide 4 text

Command Query Responsibility Segregation

Slide 5

Slide 5 text

Command Query Responsibility Segregation

Slide 6

Slide 6 text

new AddCredits($userId, $amount); Command

Slide 7

Slide 7 text

Command new AddCredits($userId, $amount); Query new GetCredits($userId);

Slide 8

Slide 8 text

Event Sourcing

Slide 9

Slide 9 text

http://www.martinfowler.com/eaaDev/EventSourcing.html „ ensures that all changes to application state are stored as a sequence of events

Slide 10

Slide 10 text

Not just can we query these events, we can also use the event log to reconstruct past states http://www.martinfowler.com/eaaDev/EventSourcing.html „

Slide 11

Slide 11 text

Commad Event Model Event Storage Event Bus Command Handler Listeners Read Storage Read Model Query

Slide 12

Slide 12 text

Commad Event Model Event Storage Event Bus Command Handler Listeners Read Storage Read Model Query Critical section - use transaction

Slide 13

Slide 13 text

Commad Event Model Event Storage Event Bus Command Handler Listeners Read Storage Read Model Query Critical section - use transaction Treat like temporary cache

Slide 14

Slide 14 text

That’s all

Slide 15

Slide 15 text

E-Wallet Credits; Invoices; Refunds

Slide 16

Slide 16 text

Wallet Credits Bonus Credits Refund Credits EXPIRE: X DAYS EXPIRE: X DAYS EXPIRE: X DAYS INVOICE: YES/NO INVOICE: YES/NO INVOICE: YES/NO

Slide 17

Slide 17 text

Wallet Credits Bonus Credits Refund Credits EXPIRE: NEVER EXPIRE: 90 DAYS EXPIRE: 90 DAYS INVOICE: YES INVOICE: NO INVOICE: YES

Slide 18

Slide 18 text

Opis walleta w Polsce specyfikacja komenty enventy Commands

Slide 19

Slide 19 text

Add Wallet Credits Add Bonus Credits Add Refund Credits

Slide 20

Slide 20 text

Sub Wallet Credits Sub Bonus Credits Sub Refund Credits SubCredits

Slide 21

Slide 21 text

Opis walleta w Polsce specyfikacja komenty enventy Events

Slide 22

Slide 22 text

Wallet CreditsWasAdded Bonus CreditsWasAdded Refund CreditsWasAdded

Slide 23

Slide 23 text

Wallet CreditsWasSubtracted Bonus CreditsWasSubtracted Refund CreditsWasSubtracted

Slide 24

Slide 24 text

specyfikacja komenty enventy 7 commands 6 events

Slide 25

Slide 25 text

specyfikacja komenty enventy What about other stuff?

Slide 26

Slide 26 text

Commad Event Model Event Storage Event Bus Command Handler Listeners Read Storage Read Model Query ?

Slide 27

Slide 27 text

Broadway komponenty Broadway https://github.com/qandidate-labs/broadway

Slide 28

Slide 28 text

Auditing log whether commands were successful or not

Slide 29

Slide 29 text

CommandHandling Provides the interface and a CommandHandler base class for handling events

Slide 30

Slide 30 text

Domain domain abstractions of the Broadway framework including the aggregate root, domain messages and domain events.

Slide 31

Slide 31 text

EventDispatcher The component provides an event dispatcher interface and a simple implementation

Slide 32

Slide 32 text

EventHandling provides interfaces for an event bus and event listeners, but also an implementation of a simple event bus and an event bus that will record published events

Slide 33

Slide 33 text

EventSourcing Provides base classes for event sourced aggregate roots and entities, an event sourced repository implementation and testing helpers.

Slide 34

Slide 34 text

EventStore implementation based on doctrine/dbal to store events in a relational database and an in-memory implementation that is useful for using in tests

Slide 35

Slide 35 text

ReadModel provides storage for your read models, a projector implementation to create read models from event streams and testing helpers.

Slide 36

Slide 36 text

Repository Component providing an abstraction of the storage of aggregates.

Slide 37

Slide 37 text

Serializers provides a simple serializer interface and a serializer implementation based on "handwritten" serializers

Slide 38

Slide 38 text

Commad Event Model Event Storage Event Bus Command Handler Listeners Read Storage Read Model Query Broadway

Slide 39

Slide 39 text

Adding Wallet Credits

Slide 40

Slide 40 text

No content

Slide 41

Slide 41 text

No content

Slide 42

Slide 42 text

Credits Query

Slide 43

Slide 43 text

No content

Slide 44

Slide 44 text

No content

Slide 45

Slide 45 text

Lessons Learned

Slide 46

Slide 46 text

Small Steps Don’t try to CQRS/EventSource everything

Slide 47

Slide 47 text

Keep It Simple Avoid names like BonusCreditsWasSubtractedBecauseAdminHitSubtractBonusCr editsInAdminPanelEvent

Slide 48

Slide 48 text

Event Storming is not that easy as it sounds

Slide 49

Slide 49 text

It’s not RDBM Remember about analysts

Slide 50

Slide 50 text

Code changes Events handle changes to data, what about changes to code?

Slide 51

Slide 51 text

Synchronize Remember about synchronizing read layer - especially after fail

Slide 52

Slide 52 text

Commad Event Model Event Storage Event Bus Command Handler Listeners Read Storage Read Model Query Critical section - use transaction

Slide 53

Slide 53 text

Performance is not an issue - for this case

Slide 54

Slide 54 text

Timezone Agnostic Implement your own EventStore if you want timezone aware records

Slide 55

Slide 55 text

Our Team

Slide 56

Slide 56 text

Paid Features

Slide 57

Slide 57 text

Next challenge Open source Paid Features libraries with Hexagonal Architecture in mind

Slide 58

Slide 58 text

Team Lead PHP Dev Junior PHP Dev You ?

Slide 59

Slide 59 text

Łukasz Szymański Development Team Lead at @szymanskilukasz http://szymanskilukasz.github.io/ https://www.linkedin.com/in/szymanskilukasz https://twitter.com/szymanskilukasz