Slide 1

Slide 1 text

11º PHPSC InCompany

Slide 2

Slide 2 text

Guilherme Augusto Henschel a.k.a. Cenoura developer since 2009 working @ Nexaas

Slide 3

Slide 3 text

Notice ✘ this talk intent is to open your mind ✘ use these patterns carefully ✘ remember, there is no silver bullet

Slide 4

Slide 4 text

ORM Customer Memory Database Customer Account owns name address account Account accountNumber type balance

Slide 5

Slide 5 text

Event Sourcing

Slide 6

Slide 6 text

“ Event Sourcing ensures that all changes to application state are stored as a sequence of events. — Martin Fowler

Slide 7

Slide 7 text

AccountCreated id: 123 owner: Guilherme H. 1 DepositPerformed accountId: 123 amount: $50 2 WithdrawalPerformed accountId: 123 amount: $20 3

Slide 8

Slide 8 text

Pros ✘ complete log of every state change ✘ easy way to undo things ✘ testing, traceability and debugability ✘ business and data analysis of event streams ✘ immutability

Slide 9

Slide 9 text

Cons ✘ complexity ✘ time to get used to ✘ limited support from frameworks

Slide 10

Slide 10 text

When ✘ rich object-oriented domain models ✘ critical accountability and debugability ✘ version control for data ✘ data can give you competitive advantage ✘ building scaleable systems based on CQRS pattern

Slide 11

Slide 11 text

CQS Command Query Segregation

Slide 12

Slide 12 text

“ every method should either be a command that performs an action, or a query that returns data to the caller, but not both. — Bertrand Meyer

Slide 13

Slide 13 text

CQRS Command Query Responsibility Segregation

Slide 14

Slide 14 text

“ creating two objects where there was previously only one

Slide 15

Slide 15 text

Before

Slide 16

Slide 16 text

Improving

Slide 17

Slide 17 text

After

Slide 18

Slide 18 text

Pros ✘ scalability ✘ flexibility ✘ reduced complexity ✘ concentrate on domain/business

Slide 19

Slide 19 text

Cons ✘ complexity

Slide 20

Slide 20 text

When ✘ task based user interfaces ✘ complex data processing ✘ disparity in reads and writes

Slide 21

Slide 21 text

Event Sourcing + CQRS

Slide 22

Slide 22 text

No content

Slide 23

Slide 23 text

Libs/Components ✘Broadway - https://github.com/broadway/ broadway ✘Prooph - http://getprooph.org/

Slide 24

Slide 24 text

thanks! guilhermeaugusto.com.br

Slide 25

Slide 25 text

References ✘ Greg Young talk - https://www.youtube.com/watch?v=JHGkaShoyNs and https://cqrs.files.wordpress.com/2010/11/cqrs_documents.pdf ✘ Johannes Seitz talk - https://ookami86.github.io/event-sourcing-in- practice/ ✘ Martin Fowler articles - https://martinfowler.com/eaaDev/ EventSourcing.html and https://martinfowler.com/bliki/CQRS.html ✘ Marco Pivetta talk - https://www.youtube.com/watch?v=8NuHNtwjync ✘ http://www.cqrs.nu/ ✘ https://speakerdeck.com/owolf/cqrs-for-great-good ✘ https://speakerdeck.com/mattketmo/cqrs-and-event-sourcing