source with kafka cqrs and event and eclipse vert · command-query separation. confidential...

77
CONFIDENTIAL Designator 1 MIcroservices Data Patterns CQRS and Event Source with Kafka and Eclipse Vert.x Don Schenck digital evangelist

Upload: others

Post on 22-Jul-2020

8 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Source with Kafka CQRS and Event and Eclipse Vert · Command-Query Separation. CONFIDENTIAL Designator “Asking a question should not change the answer” -- Bertrand Meyer. CONFIDENTIAL

CONFIDENTIAL Designator

1

MIcroservices Data Patterns

CQRS and Event Source with Kafka and Eclipse Vert.x

Don Schenckdigital evangelist

Page 2: Source with Kafka CQRS and Event and Eclipse Vert · Command-Query Separation. CONFIDENTIAL Designator “Asking a question should not change the answer” -- Bertrand Meyer. CONFIDENTIAL

CONFIDENTIAL Designator

Code is easy...

2

Unless it’s RPG III

Page 3: Source with Kafka CQRS and Event and Eclipse Vert · Command-Query Separation. CONFIDENTIAL Designator “Asking a question should not change the answer” -- Bertrand Meyer. CONFIDENTIAL

CONFIDENTIAL Designator

Code is easy...

...Data is HARD

3

Page 4: Source with Kafka CQRS and Event and Eclipse Vert · Command-Query Separation. CONFIDENTIAL Designator “Asking a question should not change the answer” -- Bertrand Meyer. CONFIDENTIAL

CONFIDENTIAL Designator

Data Everywhere:

4

Page 5: Source with Kafka CQRS and Event and Eclipse Vert · Command-Query Separation. CONFIDENTIAL Designator “Asking a question should not change the answer” -- Bertrand Meyer. CONFIDENTIAL

CONFIDENTIAL Designator

Data Everywhere:RDBMS

5

Page 6: Source with Kafka CQRS and Event and Eclipse Vert · Command-Query Separation. CONFIDENTIAL Designator “Asking a question should not change the answer” -- Bertrand Meyer. CONFIDENTIAL

CONFIDENTIAL Designator

Data Everywhere:RDBMSNoSQL

6

Page 7: Source with Kafka CQRS and Event and Eclipse Vert · Command-Query Separation. CONFIDENTIAL Designator “Asking a question should not change the answer” -- Bertrand Meyer. CONFIDENTIAL

CONFIDENTIAL Designator

Data Everywhere:RDBMSNoSQLFlat files

7

Page 8: Source with Kafka CQRS and Event and Eclipse Vert · Command-Query Separation. CONFIDENTIAL Designator “Asking a question should not change the answer” -- Bertrand Meyer. CONFIDENTIAL

CONFIDENTIAL Designator

Data Everywhere:RDBMSNoSQLFlat files (including spreadsheets!)

8

Ugh. Make it stop.

Page 9: Source with Kafka CQRS and Event and Eclipse Vert · Command-Query Separation. CONFIDENTIAL Designator “Asking a question should not change the answer” -- Bertrand Meyer. CONFIDENTIAL

CONFIDENTIAL Designator

Centralized App + Centralized Data = “Everything’s fine”

9

Page 10: Source with Kafka CQRS and Event and Eclipse Vert · Command-Query Separation. CONFIDENTIAL Designator “Asking a question should not change the answer” -- Bertrand Meyer. CONFIDENTIAL

CONFIDENTIAL Designator

But then ...

10

Page 11: Source with Kafka CQRS and Event and Eclipse Vert · Command-Query Separation. CONFIDENTIAL Designator “Asking a question should not change the answer” -- Bertrand Meyer. CONFIDENTIAL

CONFIDENTIAL Designator

11

Page 12: Source with Kafka CQRS and Event and Eclipse Vert · Command-Query Separation. CONFIDENTIAL Designator “Asking a question should not change the answer” -- Bertrand Meyer. CONFIDENTIAL

CONFIDENTIAL Designator

12

Page 13: Source with Kafka CQRS and Event and Eclipse Vert · Command-Query Separation. CONFIDENTIAL Designator “Asking a question should not change the answer” -- Bertrand Meyer. CONFIDENTIAL

CONFIDENTIAL Designator

13

Page 14: Source with Kafka CQRS and Event and Eclipse Vert · Command-Query Separation. CONFIDENTIAL Designator “Asking a question should not change the answer” -- Bertrand Meyer. CONFIDENTIAL

CONFIDENTIAL Designator

14

Remember: The “S” in IoT stands for “Security”

Page 15: Source with Kafka CQRS and Event and Eclipse Vert · Command-Query Separation. CONFIDENTIAL Designator “Asking a question should not change the answer” -- Bertrand Meyer. CONFIDENTIAL

CONFIDENTIAL Designator

https://developers.redhat.com/books/migrating-microservice-databases-relational-monolith-distributed-data/

Page 16: Source with Kafka CQRS and Event and Eclipse Vert · Command-Query Separation. CONFIDENTIAL Designator “Asking a question should not change the answer” -- Bertrand Meyer. CONFIDENTIAL

CONFIDENTIAL Designator

Split data from RDBMS

Page 17: Source with Kafka CQRS and Event and Eclipse Vert · Command-Query Separation. CONFIDENTIAL Designator “Asking a question should not change the answer” -- Bertrand Meyer. CONFIDENTIAL

CONFIDENTIAL Designator

Apps change; data tends to stick around

Page 18: Source with Kafka CQRS and Event and Eclipse Vert · Command-Query Separation. CONFIDENTIAL Designator “Asking a question should not change the answer” -- Bertrand Meyer. CONFIDENTIAL

CONFIDENTIAL Designator

You always have data.

Page 19: Source with Kafka CQRS and Event and Eclipse Vert · Command-Query Separation. CONFIDENTIAL Designator “Asking a question should not change the answer” -- Bertrand Meyer. CONFIDENTIAL

CONFIDENTIAL Designator

A decade (or so) ago:ORM - HibernatePOJOs and XML

Page 20: Source with Kafka CQRS and Event and Eclipse Vert · Command-Query Separation. CONFIDENTIAL Designator “Asking a question should not change the answer” -- Bertrand Meyer. CONFIDENTIAL

CONFIDENTIAL Designator

Then … Event Sourcing came along

Page 21: Source with Kafka CQRS and Event and Eclipse Vert · Command-Query Separation. CONFIDENTIAL Designator “Asking a question should not change the answer” -- Bertrand Meyer. CONFIDENTIAL

CONFIDENTIAL Designator

Think “Events” instead of “Data Structure”.

Page 22: Source with Kafka CQRS and Event and Eclipse Vert · Command-Query Separation. CONFIDENTIAL Designator “Asking a question should not change the answer” -- Bertrand Meyer. CONFIDENTIAL

CONFIDENTIAL Designator

ID customerID balance

1001 990 1000

1002 991 0

1003 991 -500

1004 992 300

Account

Page 23: Source with Kafka CQRS and Event and Eclipse Vert · Command-Query Separation. CONFIDENTIAL Designator “Asking a question should not change the answer” -- Bertrand Meyer. CONFIDENTIAL

CONFIDENTIAL Designator

{

"event": "transferFunds",

"fromAccountID": 1001,

"toAccountID": 1001,

"amount": 500.00,

"timestamp": "2019-08-14T11:05:27:23.000212"

}

Page 24: Source with Kafka CQRS and Event and Eclipse Vert · Command-Query Separation. CONFIDENTIAL Designator “Asking a question should not change the answer” -- Bertrand Meyer. CONFIDENTIAL

CONFIDENTIAL Designator

An Event is based on the real world, not IT-think.

Page 25: Source with Kafka CQRS and Event and Eclipse Vert · Command-Query Separation. CONFIDENTIAL Designator “Asking a question should not change the answer” -- Bertrand Meyer. CONFIDENTIAL

CONFIDENTIAL Designator

CQSCommand-Query Separation

Page 26: Source with Kafka CQRS and Event and Eclipse Vert · Command-Query Separation. CONFIDENTIAL Designator “Asking a question should not change the answer” -- Bertrand Meyer. CONFIDENTIAL

CONFIDENTIAL Designator

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

Page 27: Source with Kafka CQRS and Event and Eclipse Vert · Command-Query Separation. CONFIDENTIAL Designator “Asking a question should not change the answer” -- Bertrand Meyer. CONFIDENTIAL

CONFIDENTIAL Designator

CQRS - Command Query Responsibility Segregation

Page 28: Source with Kafka CQRS and Event and Eclipse Vert · Command-Query Separation. CONFIDENTIAL Designator “Asking a question should not change the answer” -- Bertrand Meyer. CONFIDENTIAL

CONFIDENTIAL Designator

A simple, basic example

Page 29: Source with Kafka CQRS and Event and Eclipse Vert · Command-Query Separation. CONFIDENTIAL Designator “Asking a question should not change the answer” -- Bertrand Meyer. CONFIDENTIAL

CONFIDENTIAL Designator

This is simple?

Page 30: Source with Kafka CQRS and Event and Eclipse Vert · Command-Query Separation. CONFIDENTIAL Designator “Asking a question should not change the answer” -- Bertrand Meyer. CONFIDENTIAL

CONFIDENTIAL Designator

But distributed systems bring complexity...

Page 31: Source with Kafka CQRS and Event and Eclipse Vert · Command-Query Separation. CONFIDENTIAL Designator “Asking a question should not change the answer” -- Bertrand Meyer. CONFIDENTIAL

CONFIDENTIAL Designator

Page 32: Source with Kafka CQRS and Event and Eclipse Vert · Command-Query Separation. CONFIDENTIAL Designator “Asking a question should not change the answer” -- Bertrand Meyer. CONFIDENTIAL

CONFIDENTIAL Designator

Examples:● Read one● Read a list● Search...

Page 33: Source with Kafka CQRS and Event and Eclipse Vert · Command-Query Separation. CONFIDENTIAL Designator “Asking a question should not change the answer” -- Bertrand Meyer. CONFIDENTIAL

CONFIDENTIAL Designator

CQRS & Event Sourcing

Page 34: Source with Kafka CQRS and Event and Eclipse Vert · Command-Query Separation. CONFIDENTIAL Designator “Asking a question should not change the answer” -- Bertrand Meyer. CONFIDENTIAL

CONFIDENTIAL Designator

Why CQRS?

Page 35: Source with Kafka CQRS and Event and Eclipse Vert · Command-Query Separation. CONFIDENTIAL Designator “Asking a question should not change the answer” -- Bertrand Meyer. CONFIDENTIAL

CONFIDENTIAL Designator

Performance

Page 36: Source with Kafka CQRS and Event and Eclipse Vert · Command-Query Separation. CONFIDENTIAL Designator “Asking a question should not change the answer” -- Bertrand Meyer. CONFIDENTIAL

CONFIDENTIAL Designator

...and...

Page 37: Source with Kafka CQRS and Event and Eclipse Vert · Command-Query Separation. CONFIDENTIAL Designator “Asking a question should not change the answer” -- Bertrand Meyer. CONFIDENTIAL

CONFIDENTIAL Designator

● Distribution● Availability● Integration● Analytics

Page 38: Source with Kafka CQRS and Event and Eclipse Vert · Command-Query Separation. CONFIDENTIAL Designator “Asking a question should not change the answer” -- Bertrand Meyer. CONFIDENTIAL

CONFIDENTIAL Designator

WHEN CQRS?

Page 39: Source with Kafka CQRS and Event and Eclipse Vert · Command-Query Separation. CONFIDENTIAL Designator “Asking a question should not change the answer” -- Bertrand Meyer. CONFIDENTIAL

CONFIDENTIAL Designator

Single Source of Truth: The WRITE data store

Page 40: Source with Kafka CQRS and Event and Eclipse Vert · Command-Query Separation. CONFIDENTIAL Designator “Asking a question should not change the answer” -- Bertrand Meyer. CONFIDENTIAL

CONFIDENTIAL Designator

Next: Create your READ data stores.

Page 41: Source with Kafka CQRS and Event and Eclipse Vert · Command-Query Separation. CONFIDENTIAL Designator “Asking a question should not change the answer” -- Bertrand Meyer. CONFIDENTIAL

CONFIDENTIAL Designator

Add Events to update data stores.

Page 42: Source with Kafka CQRS and Event and Eclipse Vert · Command-Query Separation. CONFIDENTIAL Designator “Asking a question should not change the answer” -- Bertrand Meyer. CONFIDENTIAL

CONFIDENTIAL Designator

More about Event Sourcing:

Page 43: Source with Kafka CQRS and Event and Eclipse Vert · Command-Query Separation. CONFIDENTIAL Designator “Asking a question should not change the answer” -- Bertrand Meyer. CONFIDENTIAL

CONFIDENTIAL Designator

It’s WRITE-ONLY

Page 44: Source with Kafka CQRS and Event and Eclipse Vert · Command-Query Separation. CONFIDENTIAL Designator “Asking a question should not change the answer” -- Bertrand Meyer. CONFIDENTIAL

CONFIDENTIAL Designator

You get audit trails/history built in

Well … that’s nice

Page 45: Source with Kafka CQRS and Event and Eclipse Vert · Command-Query Separation. CONFIDENTIAL Designator “Asking a question should not change the answer” -- Bertrand Meyer. CONFIDENTIAL

CONFIDENTIAL Designator

Events are immutable

Page 46: Source with Kafka CQRS and Event and Eclipse Vert · Command-Query Separation. CONFIDENTIAL Designator “Asking a question should not change the answer” -- Bertrand Meyer. CONFIDENTIAL

CONFIDENTIAL Designator

The Event Store fires events that are independent of the origin

So convenient. I guess it’s a convenience store yuk yuk

Page 47: Source with Kafka CQRS and Event and Eclipse Vert · Command-Query Separation. CONFIDENTIAL Designator “Asking a question should not change the answer” -- Bertrand Meyer. CONFIDENTIAL

CONFIDENTIAL Designator

Events...

Page 48: Source with Kafka CQRS and Event and Eclipse Vert · Command-Query Separation. CONFIDENTIAL Designator “Asking a question should not change the answer” -- Bertrand Meyer. CONFIDENTIAL

CONFIDENTIAL Designator

Maintain a Materialized View

Page 49: Source with Kafka CQRS and Event and Eclipse Vert · Command-Query Separation. CONFIDENTIAL Designator “Asking a question should not change the answer” -- Bertrand Meyer. CONFIDENTIAL

CONFIDENTIAL Designator

Integrate external systems

Page 50: Source with Kafka CQRS and Event and Eclipse Vert · Command-Query Separation. CONFIDENTIAL Designator “Asking a question should not change the answer” -- Bertrand Meyer. CONFIDENTIAL

CONFIDENTIAL Designator

Are not reliant on a database schema

Page 51: Source with Kafka CQRS and Event and Eclipse Vert · Command-Query Separation. CONFIDENTIAL Designator “Asking a question should not change the answer” -- Bertrand Meyer. CONFIDENTIAL

CONFIDENTIAL Designator

Can materialize the current state(This can be a batch job!)

Page 52: Source with Kafka CQRS and Event and Eclipse Vert · Command-Query Separation. CONFIDENTIAL Designator “Asking a question should not change the answer” -- Bertrand Meyer. CONFIDENTIAL

CONFIDENTIAL Designator

Events follow the “Fire-and-Forget” model of operation.

Page 53: Source with Kafka CQRS and Event and Eclipse Vert · Command-Query Separation. CONFIDENTIAL Designator “Asking a question should not change the answer” -- Bertrand Meyer. CONFIDENTIAL

CONFIDENTIAL Designator

It was time for another pretty picture

Page 54: Source with Kafka CQRS and Event and Eclipse Vert · Command-Query Separation. CONFIDENTIAL Designator “Asking a question should not change the answer” -- Bertrand Meyer. CONFIDENTIAL

CONFIDENTIAL Designator

Somethings that affect your decision regarding updating READ stores:

Page 55: Source with Kafka CQRS and Event and Eclipse Vert · Command-Query Separation. CONFIDENTIAL Designator “Asking a question should not change the answer” -- Bertrand Meyer. CONFIDENTIAL

CONFIDENTIAL Designator

Latency

Page 56: Source with Kafka CQRS and Event and Eclipse Vert · Command-Query Separation. CONFIDENTIAL Designator “Asking a question should not change the answer” -- Bertrand Meyer. CONFIDENTIAL

CONFIDENTIAL Designator

Size

Page 57: Source with Kafka CQRS and Event and Eclipse Vert · Command-Query Separation. CONFIDENTIAL Designator “Asking a question should not change the answer” -- Bertrand Meyer. CONFIDENTIAL

CONFIDENTIAL Designator

Staleness

Page 58: Source with Kafka CQRS and Event and Eclipse Vert · Command-Query Separation. CONFIDENTIAL Designator “Asking a question should not change the answer” -- Bertrand Meyer. CONFIDENTIAL

CONFIDENTIAL Designator

Ownership

Page 59: Source with Kafka CQRS and Event and Eclipse Vert · Command-Query Separation. CONFIDENTIAL Designator “Asking a question should not change the answer” -- Bertrand Meyer. CONFIDENTIAL

CONFIDENTIAL Designator

Security

Page 60: Source with Kafka CQRS and Event and Eclipse Vert · Command-Query Separation. CONFIDENTIAL Designator “Asking a question should not change the answer” -- Bertrand Meyer. CONFIDENTIAL

CONFIDENTIAL Designator

Nature and depth of information

Page 61: Source with Kafka CQRS and Event and Eclipse Vert · Command-Query Separation. CONFIDENTIAL Designator “Asking a question should not change the answer” -- Bertrand Meyer. CONFIDENTIAL

CONFIDENTIAL Designator

So how do we find the current state?

Page 62: Source with Kafka CQRS and Event and Eclipse Vert · Command-Query Separation. CONFIDENTIAL Designator “Asking a question should not change the answer” -- Bertrand Meyer. CONFIDENTIAL

CONFIDENTIAL Designator

Cheat Mode = ON(It’s okay to bookmark data)

Up up down down left right left right B A

Page 63: Source with Kafka CQRS and Event and Eclipse Vert · Command-Query Separation. CONFIDENTIAL Designator “Asking a question should not change the answer” -- Bertrand Meyer. CONFIDENTIAL

CONFIDENTIAL Designator

CQRS considerations:

Page 64: Source with Kafka CQRS and Event and Eclipse Vert · Command-Query Separation. CONFIDENTIAL Designator “Asking a question should not change the answer” -- Bertrand Meyer. CONFIDENTIAL

CONFIDENTIAL Designator

CQRS considerations:● Complexity

Page 65: Source with Kafka CQRS and Event and Eclipse Vert · Command-Query Separation. CONFIDENTIAL Designator “Asking a question should not change the answer” -- Bertrand Meyer. CONFIDENTIAL

CONFIDENTIAL Designator

CQRS considerations:● Complexity● Consistency

Page 66: Source with Kafka CQRS and Event and Eclipse Vert · Command-Query Separation. CONFIDENTIAL Designator “Asking a question should not change the answer” -- Bertrand Meyer. CONFIDENTIAL

CONFIDENTIAL Designator

CQRS considerations:● Complexity● Consistency● Communication

Page 67: Source with Kafka CQRS and Event and Eclipse Vert · Command-Query Separation. CONFIDENTIAL Designator “Asking a question should not change the answer” -- Bertrand Meyer. CONFIDENTIAL

CONFIDENTIAL Designator

Distributing events using a Message Broker

Page 68: Source with Kafka CQRS and Event and Eclipse Vert · Command-Query Separation. CONFIDENTIAL Designator “Asking a question should not change the answer” -- Bertrand Meyer. CONFIDENTIAL

CONFIDENTIAL Designator

Page 69: Source with Kafka CQRS and Event and Eclipse Vert · Command-Query Separation. CONFIDENTIAL Designator “Asking a question should not change the answer” -- Bertrand Meyer. CONFIDENTIAL

CONFIDENTIAL Designator

KafkaStreaming platform (with ordered delivery)

Page 70: Source with Kafka CQRS and Event and Eclipse Vert · Command-Query Separation. CONFIDENTIAL Designator “Asking a question should not change the answer” -- Bertrand Meyer. CONFIDENTIAL

CONFIDENTIAL Designator

Kafka uses a Publish/Subscribe model with Topics

Page 71: Source with Kafka CQRS and Event and Eclipse Vert · Command-Query Separation. CONFIDENTIAL Designator “Asking a question should not change the answer” -- Bertrand Meyer. CONFIDENTIAL

CONFIDENTIAL Designator

Vert.xReactive platform

Page 72: Source with Kafka CQRS and Event and Eclipse Vert · Command-Query Separation. CONFIDENTIAL Designator “Asking a question should not change the answer” -- Bertrand Meyer. CONFIDENTIAL

CONFIDENTIAL Designator

Page 73: Source with Kafka CQRS and Event and Eclipse Vert · Command-Query Separation. CONFIDENTIAL Designator “Asking a question should not change the answer” -- Bertrand Meyer. CONFIDENTIAL

CONFIDENTIAL Designator

Page 74: Source with Kafka CQRS and Event and Eclipse Vert · Command-Query Separation. CONFIDENTIAL Designator “Asking a question should not change the answer” -- Bertrand Meyer. CONFIDENTIAL

CONFIDENTIAL Designator

Page 75: Source with Kafka CQRS and Event and Eclipse Vert · Command-Query Separation. CONFIDENTIAL Designator “Asking a question should not change the answer” -- Bertrand Meyer. CONFIDENTIAL

CONFIDENTIAL Designator

github.com/reactica/rhte-demogithub.com/vert-x3/vertx-examples

developers.redhat.com@DonSchenck

So many URLs, so little time. What’s another browser tab open between friends?

Page 76: Source with Kafka CQRS and Event and Eclipse Vert · Command-Query Separation. CONFIDENTIAL Designator “Asking a question should not change the answer” -- Bertrand Meyer. CONFIDENTIAL

CONFIDENTIAL Designator

This slide intentionally left blank

Page 77: Source with Kafka CQRS and Event and Eclipse Vert · Command-Query Separation. CONFIDENTIAL Designator “Asking a question should not change the answer” -- Bertrand Meyer. CONFIDENTIAL

CONFIDENTIAL Designator

linkedin.com/company/red-hat

youtube.com/user/RedHatVideos

facebook.com/redhatinc

twitter.com/RedHat

77

Red Hat is the world’s leading provider of enterprise

open source software solutions. Award-winning

support, training, and consulting services make Red

Hat a trusted adviser to the Fortune 500.

Thank you