Slide 1

Slide 1 text

3 Event-Driven Architecture Patterns in Action Hans-Peter Grahsl Developer Advocate Red Hat @hpgrahsl

Slide 2

Slide 2 text

What we’ll be discussing today AGENDA 2 EDA and Events Claim Check Pattern Content Enricher Pattern Message Translator Pattern

Slide 3

Slide 3 text

OpenShift Developer Sandbox! Get free access for renewable 30 days to a self-service, cloud-hosted Kubernetes experience with Developer Sandbox for Red Hat OpenShift. red.ht/sandbox4all

Slide 4

Slide 4 text

OpenShift Developer Sandbox! red.ht/sandbox4all πŸ‘‰ When signing up, use this code: 2zecv πŸ‘ˆ

Slide 5

Slide 5 text

πŸ€” Event-Driven Architecture (EDA) ? EDA Intro 5 Event-Driven Architecture (EDA) is a way of designing loosely coupled applications and services that respond in near real-time based on the sending and receiving of events.

Slide 6

Slide 6 text

This talk’s meaning of EDA EDA Intro 6

Slide 7

Slide 7 text

Multiple β€œflavours” of Event-Driven Architecture EDA Intro 7 https://martinfowler.com/articles/201701-event-driven.html

Slide 8

Slide 8 text

8 EVENTS EVENTS EVERYWHERE

Slide 9

Slide 9 text

Events and Event Design Events … or β€œsomething has happened (somewhere)” 9 ● order created (order service) ● order created with id β€˜123’ (order service) ● order created with id β€˜123’, and N products (order service) ● order created with id β€˜123’, N products, and total amount of M (order service) ● … ● order created with id β€˜123’, product A, product B,... , total amount of M, , customer with id β€˜XYZ’, and address β€˜foo blah’, … (order service)

Slide 10

Slide 10 text

Events and Event Design 10 πŸ€” Where does this end? πŸ€” πŸ›‘ When should this stop? πŸ›‘

Slide 11

Slide 11 text

Purposeful Event Design β†’ Event Type Examples Events and Event Design 11

Slide 12

Slide 12 text

Events and Event Design 12 One seeks bullets of silver … … but only finds trade-offs.

Slide 13

Slide 13 text

Up next… AGENDA 13 Claim Check Pattern Content Enricher Pattern Message Translator Pattern

Slide 14

Slide 14 text

Challenge Claim Check Pattern 14 ● (unnaturally / too) heavy payloads ? raw / binary files graphics, documents, audio, video, … embedded data (base64) within structured text formats (xml, json,…)

Slide 15

Slide 15 text

Claim Check Pattern Claim Check Pattern 15 ● offload large (binary) payload into separate storage system ● replace actual payload with reference to claim check ● use claim check to fetch data when needed at consumer side

Slide 16

Slide 16 text

Demo Scenario Claim Check Pattern 16 ● context: media processing pipeline ● images sent between services ● communication via Kafka topics ● external storage system MinIO

Slide 17

Slide 17 text

Claim Check Pattern 17 Claim Check Pattern

Slide 18

Slide 18 text

Claim Check Pattern 18 Claim Check Pattern

Slide 19

Slide 19 text

Claim Check Pattern 19 Claim Check Pattern

Slide 20

Slide 20 text

Claim Check Pattern 20 Claim Check Pattern

Slide 21

Slide 21 text

Claim Check Pattern 21 Claim Check Pattern

Slide 22

Slide 22 text

Claim Check Pattern 22 Claim Check Pattern

Slide 23

Slide 23 text

Implementation Details Claim Check Pattern 23 ● Kafka producer/consumer apps written with Quarkus ● offloading binary data delegated to specific Serde ● MinIO (S3-compatible) acts as storage system β†’ reasonably-sized payloads in order not to pollute event streaming platform with tons of binary data

Slide 24

Slide 24 text

24 Claim Check Pattern

Slide 25

Slide 25 text

Discussion Claim Check Pattern 25 ● Serde for configurable data offloading with ease ● in Kafka Connect context β†’ apply Converter ● think about object storage id generation choices ● currently full payload only β†’ no field-level scope ● to some degree it’s a dual-writes problem

Slide 26

Slide 26 text

Up next… AGENDA 26 Claim Check Pattern Content Enricher Pattern Message Translator Pattern

Slide 27

Slide 27 text

Challenge Content Enricher Pattern 27 ● (unnaturally / too) light payloads ? payloads lacking additional details certain consumers need to know more e.g. due to very compact notification events

Slide 28

Slide 28 text

Content Enricher Pattern Content Enricher Pattern 28 ● add data to original payload ● perform lookups or do joins against reference data ● take reference data to augment original payload with additional information

Slide 29

Slide 29 text

Demo Scenario Content Enricher Pattern 29 ● context: IoT sensor data processing ● raw stream contains sensor measurements only ● certain consumers need device meta-data ● sensor stream is enriched with missing data

Slide 30

Slide 30 text

Content Enricher Pattern 30

Slide 31

Slide 31 text

Content Enricher Pattern 31

Slide 32

Slide 32 text

Content Enricher Pattern 32

Slide 33

Slide 33 text

Content Enricher Pattern 33

Slide 34

Slide 34 text

Content Enricher Pattern 34

Slide 35

Slide 35 text

Content Enricher Pattern 35

Slide 36

Slide 36 text

Implementation Details Content Enricher Pattern 36 ● device data resides in MySQL table ● Kafka data ingestion by means of CDC β†’ Debezium ● Quarkus producer app simulates random sensor data ● KStreams app joins sensor data with device data ● enriched data continuously written to separate topic β†’ consumers can access and directly work with enriched data

Slide 37

Slide 37 text

Content Enricher Pattern

Slide 38

Slide 38 text

Discussion Content Enricher Pattern 38 ● augmentation possible with different tech stacks ● stream processing lib/framework recommended ● alternatively SQL abstractions might be beneficial ● enrichment kept separate from consumer ● reference data local in/close to processing app

Slide 39

Slide 39 text

Up next… AGENDA 39 Claim Check Pattern Content Enricher Pattern Message Translator Pattern

Slide 40

Slide 40 text

Challenge Message Translator Pattern 40 inconvenient / incompatible payloads ? ● minimize or at least reduce the contract-related coupling ● examples: β—‹ integrate legacy systems β—‹ work with proprietary data formats β—‹ prevent leakage of domain models

Slide 41

Slide 41 text

Message Translator Pattern Message Translator Pattern 41 ● perform a wide range of payload modifications β—‹ basic field type conversions β—‹ rename, redact, or mask fields β—‹ complete format/protocol change β—‹ … ● entity modifications between bounded contexts ● ideally β€œself-contained” operations only

Slide 42

Slide 42 text

Demo Scenario Message Translator Pattern ● context: point-of-sales record processing ● files (source) with data in proprietary CSV format ● web service (sink) expecting specific JSON format ● streaming data pipeline with in-flight transformations 42

Slide 43

Slide 43 text

Message Translator Pattern 43

Slide 44

Slide 44 text

Message Translator Pattern 44

Slide 45

Slide 45 text

Message Translator Pattern 45

Slide 46

Slide 46 text

Message Translator Pattern 46

Slide 47

Slide 47 text

Message Translator Pattern 47

Slide 48

Slide 48 text

Message Translator Pattern 48

Slide 49

Slide 49 text

Implementation Details Message Translator Pattern 49 ● streaming data pipeline with Kafka Connect β—‹ file source connector processing CSV files β—‹ http sink connector feeding JSON into web API ● message translation with Kafka Connect SMT chain β—‹ drop and rename fields β—‹ field type conversions β†’ enabler for data integration between disparate systems

Slide 50

Slide 50 text

Message Translator Pattern 50

Slide 51

Slide 51 text

Discussion Message Translator Pattern 51 ● based on Kafka Connect β†’ config only ● supports many different data sources / sinks ● various on-the-fly transformations β†’ SMT chains ● translations on either/both sides of the data flow ● no direct support for stateful processing

Slide 52

Slide 52 text

Summary of Observations in EDA EDA Summary 52 ● looser coupling, better extensibility, higher independence ● good event design needs collaboration + domain expertise ● no silver bullets for event design β†’ trade-offs ● patterns help to deal with implications / to cope with trade-offs

Slide 53

Slide 53 text

Demo Repository red.ht/eda-patterns

Slide 54

Slide 54 text

OpenShift Developer Sandbox! red.ht/sandbox4all πŸ‘‰ When signing up, use this code: 2zecv πŸ‘ˆ

Slide 55

Slide 55 text

linkedin.com/company/red-hat youtube.com/user/RedHatVideos facebook.com/redhatinc twitter.com/RedHat 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 ! 55

Slide 56

Slide 56 text

Photo Credits in order of appearance 56 https://unsplash.com/photos/DRzYMtae-vA https://pixabay.com/illustrations/night-sky-stars-moon-wolf-garou-4726445/ https://unsplash.com/photos/HTIduwcMMfQ https://unsplash.com/photos/w9rYOScXf6E https://unsplash.com/photos/iar-afB0QQw https://unsplash.com/photos/q65bNe9fW-w https://pixabay.com/photos/video-production-video-movie-film-4223885/ https://pixabay.com/photos/feather-bird-plumage-flying-4380861/ https://unsplash.com/photos/MceA9kSze0U https://pixabay.com/photos/travel-adapter-plug-charging-plug-3320763/ https://unsplash.com/photos/g97bviyFhvQ