Slide 1

Slide 1 text

Microservice Data Patterns: CQRS & Event Sourcing Edson Yanaga Director of Developer Experience @yanaga

Slide 2

Slide 2 text

Join developers.redhat.com 2 Java Champion Microsoft MVP

Slide 3

Slide 3 text

http://developers.redhat.com/promotions/ migrating-to-microservice-databases

Slide 4

Slide 4 text

Code is easy, state is hard

Slide 5

Slide 5 text

How was data managed 10 years ago?

Slide 6

Slide 6 text

Terrified about Entity Beans

Slide 7

Slide 7 text

Hibernate to the rescue!

Slide 8

Slide 8 text

Replacing XML with @Annotations

Slide 9

Slide 9 text

POJOs as an (Anemic) Domain Model

Slide 10

Slide 10 text

Event Sourcing

Slide 11

Slide 11 text

Join developers.redhat.com 11 ID CUSTOMER_ID BALANCE 1001 990 1000 1002 991 0 1003 991 -500 1004 992 300 Account

Slide 12

Slide 12 text

Join developers.redhat.com 12 ID ACCOUNT_ID TIMESTAMP OP AMOUNT 1 1001 1234567890 C 1000 2 1002 1234567891 C 200 3 1001 1234567900 D 300 4 1001 1234567995 D 150 Transactions

Slide 13

Slide 13 text

Enables you to think in the Events that happened in the system

Slide 14

Slide 14 text

CQS (Command-Query Separation) “Asking a question should not change the answer” (Bertrand Meyer)

Slide 15

Slide 15 text

“Asking a question should not change the answer” (Bertrand Meyer)

Slide 16

Slide 16 text

CQRS (Command Query Responsibility Segregation)

Slide 17

Slide 17 text

Join developers.redhat.com 17 CQRS (Command Query Responsibility Segregation)

Slide 18

Slide 18 text

Join developers.redhat.com 18 ID NAME PHONE ADDRESS BIRTH 1 Burr 222-222-2323 901 South St 12/12/1968 2 Edson 222-333-3434 112 North Dr 03/03/1978 3 John 111-456-4545 666 Iron St 06/06/1966 4 Doe 333-789-7890 777 Boeing Dr 07/07/1977 INSERT INTO CUSTOMER(ID,NAME,PHONE,ADDRESS,BIRTH); SELECT * FROM CUSTOMER;

Slide 19

Slide 19 text

Join developers.redhat.com 19 SELECT ID, NAME, PHONE FROM CUSTOMER; SELECT ID, NAME, ADDRESS FROM CUSTOMER;

Slide 20

Slide 20 text

Join developers.redhat.com 20 CQRS with separate data stores

Slide 21

Slide 21 text

Join developers.redhat.com 21 SELECT ID, NAME, AGE, AVG_BILL FROM CUSTOMER_REPORT_VIEW; SELECT ID, PHONE, LAST_PAYMENT_AMOUNT FROM CUSTOMER_BILLING_VIEW;

Slide 22

Slide 22 text

CQRS & Event Sourcing

Slide 23

Slide 23 text

Join developers.redhat.com 23 ID CUSTOMER_ID BALANCE 1001 990 1000 1002 991 0 1003 991 -500 1004 992 300 Account ID ACCOUNT_ID TIMESTAMP OP AMOUNT 1 1001 1234567890 C 1000 2 1002 1234567891 C 200 3 1001 1234567900 D 300 4 1001 1234567995 D 150 Transactions

Slide 24

Slide 24 text

Join developers.redhat.com 24 ID CUSTOMER_ID BALANCE 1001 990 1000 1002 991 0 1003 991 -500 1004 992 300 Account ID ACCOUNT_ID TIMESTAMP OP AMOUNT 1 1001 1234567890 C 1000 2 1002 1234567891 C 200 3 1001 1234567900 D 300 4 1001 1234567995 D 150 Transactions READ MODEL WRITE MODEL

Slide 25

Slide 25 text

Why CQRS?

Slide 26

Slide 26 text

Performance

Slide 27

Slide 27 text

Distribution Availability Integration Analytics

Slide 28

Slide 28 text

Join developers.redhat.com 28 Canonical Source of Information (Write Data Store)

Slide 29

Slide 29 text

Join developers.redhat.com 29 Canonical Source of Information (Write Data Store) Read Data Store Read Data Store

Slide 30

Slide 30 text

Join developers.redhat.com 30 Canonical Source of Information (Write Data Store) Read Data Store Read Data Store Events Events

Slide 31

Slide 31 text

Different choices of technology depending on the requirements

Slide 32

Slide 32 text

Latency Size Staleness Ownership Security Type?

Slide 33

Slide 33 text

Join developers.redhat.com 33 http://infinispan.org/ In-memory Data Grids

Slide 34

Slide 34 text

Join developers.redhat.com 34 http://teiid.jboss.org/ Data Virtualization

Slide 35

Slide 35 text

Join developers.redhat.com 35 http://activemq.apache.org/ Message Brokers https://kafka.apache.org/

Slide 36

Slide 36 text

Join developers.redhat.com 36 http://vertx.io/ Reactive Platform

Slide 37

Slide 37 text

Join developers.redhat.com 37 REMOTE API

Slide 38

Slide 38 text

Join developers.redhat.com 38 REMOTE API REACTIVE

Slide 39

Slide 39 text

Join developers.redhat.com 39 http://debezium.io/ Change Data Capture

Slide 40

Slide 40 text

Join developers.redhat.com Feedback welcome! @yanaga

Slide 41

Slide 41 text

plus.google.com/+RedHat linkedin.com/company/red-hat youtube.com/user/RedHatVideos facebook.com/redhatinc twitter.com/RedHatNews Thank you!