Distribute Your Microservices Data With Events, CQRS, and Event Sourcing

Distribute Your Microservices Data With Events, CQRS, and Event Sourcing

You split up your monolithic codebase into smaller artifacts and thought you were done! Now you’ve reached the hardest part: how do you split your data, and how do you keep your system working with it?

If this rings a bell, then you need to register for this session. We’ll explore how events with an event-driven architecture can help you succeed in this distributed data world. Learn concepts like CQRS, event sourcing, and how you can use them in a distributed architecture with REST, message brokers, and Apache Kafka.

14493d3489b1441918bfddfe298415d9?s=128

Edson Yanaga

January 16, 2020
Tweet

Transcript

  1. Distributed Your Microservices Data With Events, CQRS, and Event Sourcing

    Edson Yanaga @yanaga
  2. @yanaga 2 @yanaga

  3. @yanaga 3 bit.ly/mono2microdb

  4. @yanaga 4 Code is easy, state is hard

  5. @yanaga 5 HTTP + REST/gRPC/RMI/IIOP Synchronous Data Retrieval on a

    Remote Endpoint Client Canonical Source of Information
  6. @yanaga 6 HTTP + REST/gRPC/RMI/IIOP Synchronous Data Retrieval on a

    Remote Endpoint Client Canonical Source of Information
  7. @yanaga 7 Latency Availability Performance

  8. @yanaga 8 Cache and/or Polling

  9. @yanaga 9 Eventual Consistency

  10. @yanaga 10 Eventual Consistency

  11. @yanaga 11 First, a look back at the past…

  12. @yanaga 12 How was data managed 10 years ago?

  13. @yanaga 13 Terrified about Entity Beans

  14. @yanaga 14 Hibernate to the rescue!

  15. @yanaga 15 Replacing XML with @Annotations

  16. @yanaga 16 POJOs as an (Anemic) Domain Model

  17. @yanaga 17 Event Sourcing

  18. @yanaga 18 ID CUSTOMER_ID BALANCE 1001 990 1000 1002 991

    0 1003 991 -500 1004 992 300 Account
  19. @yanaga 19 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
  20. @yanaga 20 Enables you to think in the Events that

    happened in the system
  21. @yanaga 21 CQS (Command-Query Separation) “Asking a question should not

    change the answer” (Bertrand Meyer)
  22. @yanaga 22 CQRS (Command Query Responsibility Segregation)

  23. @yanaga 23 CQRS (Command Query Responsibility Segregation)

  24. @yanaga 24 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;
  25. @yanaga 25 SELECT ID, NAME, PHONE FROM CUSTOMER; SELECT ID,

    NAME, ADDRESS FROM CUSTOMER;
  26. @yanaga 26 CQRS with separate data stores

  27. @yanaga 27 SELECT ID, NAME, AGE, AVG_BILL FROM CUSTOMER_REPORT_VIEW; SELECT

    ID, PHONE, LAST_PAYMENT_AMOUNT FROM CUSTOMER_BILLING_VIEW;
  28. @yanaga 28 CQRS & Event Sourcing

  29. @yanaga 29 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
  30. @yanaga 30 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
  31. @yanaga 31 Why CQRS?

  32. @yanaga 32 Performance

  33. @yanaga 33 Now, Back to the Future!

  34. @yanaga 34 Distribution Availability Integration Analytics

  35. @yanaga 35 Canonical Source of Information (Write Data Store) µ

  36. @yanaga 36 Canonical Source of Information (Write Data Store) Read

    Data Store Read Data Store µ µ µ
  37. @yanaga 37 Canonical Source of Information (Write Data Store) Read

    Data Store Read Data Store µ µ µ Events Events
  38. @yanaga 38 HTTP + REST/gRPC/RMI/IIOP Synchronous Event Retrieval Client Canonical

    Source of Information µ µ
  39. @yanaga 39 HTTP + REST/gRPC/RMI/IIOP Synchronous Event Retrieval Client Canonical

    Source of Information µ µ
  40. @yanaga 40 AMQP/Kafka Asynchronous Event Propagation Client Canonical Source of

    Information µ µ
  41. @yanaga 41 Approaches

  42. @yanaga 42 1st: You need change events (Event Sourcing)

  43. @yanaga 43 Change your application OR Use Debezium

  44. @yanaga 44 2nd: You need to distribute the events

  45. @yanaga 45 Create a REST endpoint for your events using

    Quarkus Or Publish the events on ActiveMQ / Kafka
  46. @yanaga 46 3rd: Consume the events and update your local

    CQRS data store
  47. @yanaga 47 4th: Use the local data in your local

    CQRS data store
  48. @yanaga 48 Thank you!