The Tales of Event-Driven Told by a Spring Developer

A presentation at SpringOne 2020 in September 2020 in by Viktor Gamov

Slide 1

Slide 1

The Tales of Event-Driven Told by a Spring Developer September 2020 / SpringOne @gamussa | #springone | @confluentinc

Slide 2

Slide 2

@gamussa | #springone | @confluentinc

Slide 3

Slide 3

Preface @gamussa | #springone | @confluentinc

Slide 4

Slide 4

Photo by Khai Sze Ong on Unsplash

Slide 5

Slide 5

Photo by Rainier Ridao on Unsplash \

Slide 6

Slide 6

Photo by Rohit Tandon on Unsplash

Slide 7

Slide 7

Photo by Theodore Moore on Unsplash

Slide 8

Slide 8

Photo by Cristian Grecu on Unsplash

Slide 9

Slide 9

@gamussa | #springone | @confluentinc

Slide 10

Slide 10

Refactoring to microservices

Slide 11

Slide 11

It used to be so simple…

Slide 12

Slide 12

@gamussa | #springone | @confluentinc

Slide 13

Slide 13

Normal Applications (i.e., monoliths) @gamussa | #springone | @confluentinc

Slide 14

Slide 14

Monoliths are hard to think about @gamussa | #springone | @confluentinc

Slide 15

Slide 15

Monoliths are hard to change @gamussa | #springone | @confluentinc

Slide 16

Slide 16

Re-integration? @gamussa | #springone | @confluentinc

Slide 17

Slide 17

Re-integration @gamussa | #springone | @confluentinc

Slide 18

Slide 18

Photo by Deva Darshan from Pexels

Slide 19

Slide 19

There are no good ways to integrate microservices @gamussa | #springone | @confluentinc

Slide 20

Slide 20

There are no-good ways to integrate microservices @gamussa | #springone | @confluentinc

Slide 21

Slide 21

Filesystem @gamussa | #springone | @confluentinc

Slide 22

Slide 22

@gamussa | #springone | @confluentinc

Slide 23

Slide 23

Database @gamussa | #springone | @confluentinc

Slide 24

Slide 24

@gamussa | #springone | @confluentinc

Slide 25

Slide 25

Integrating Microservices through the database • “I have a database and I know how to use it.” • Eventually causes services to co-mingle. • Violation the «bounded context» • Great to use inside a service boundary! • Terrible for sharing data or negotiating change. @gamussa | #springone | @confluentinc

Slide 26

Slide 26

RPC @gamussa | #springone | @confluentinc

Slide 27

Slide 27

@gamussa | #springone | @confluentinc

Slide 28

Slide 28

Integrating microservices via RPC • Avoids problems of database integration • Feels natural • Aligns with the request/ response paradigm • Problem: cascading failures • Question: how do you debug this system? 🤔 • Answer: you build a log. @gamussa | #springone | @confluentinc

Slide 29

Slide 29

Log4j type of log? @gamussa | #springone | @confluentinc 🤔

Slide 30

Slide 30

Events? @gamussa | #springone | @confluentinc

Slide 31

Slide 31

What’s an event? @gamussa | #springone | @confluentinc

Slide 32

Slide 32

an occurrence, especially one of some importance. @gamussa | #springone | @confluentinc

Slide 33

Slide 33

A combination of: Notification State transfer @gamussa | #springone | @confluentinc

Slide 34

Slide 34

Also, events are immutable. @gamussa | #springone | @confluentinc

Slide 35

Slide 35

Core abstraction @gamussa • DB - table • Hadoop file • Kafka - ? | #springone | @confluentinc

Slide 36

Slide 36

LOG @gamussa | #springone | @confluentinc

Slide 37

Slide 37

Slide 38

Slide 38

A Richer Microservices Application @gamussa | #springone | @confluentinc

Slide 39

Slide 39

@gamussa | #springone | @confluentinc

Slide 40

Slide 40

Ratings Service operating on the event stream Browser ratings Ratings Service Webserver Order rawRequested rating ratings ratings counts KStreams API used to count and sum ratings as they arrive ratings sums KAFKA @gamussa | @ #springone | @confluentinc

Slide 41

Slide 41

Schema Management Browser ratings Ratings Service Webserver Order rawRequested rating ratings ratings counts KStreams API used to count and sum ratings as they arrive ratings sums KAFKA @gamussa | @ #springone | @confluentinc Schema Registry

Slide 42

Slide 42

Access legacy relation data Browser ratings Ratings Service Webserver Order rawRequested rating Connect ratings ratings counts KStreams API used to count and sum ratings as they arrive ratings sums KAFKA @gamussa | @ #springone | @confluentinc Movies Schema Registry

Slide 43

Slide 43

Materialize tables inside the app Browser ratings Ratings Service Movies Lookup table created inside the Rating Service Webserver Order rawRequested rating Connect ratings ratings counts ratings sums KAFKA @gamussa | @ #springone | @confluentinc Movies Schema Registry

Slide 44

Slide 44

Create a new table, persist it to the log Browser ratings rated-movies Ratings Service Writable table created for rated movies Movies Webserver Order rawRequested rating Connect ratings ratings counts ratings sums KAFKA @gamussa | @ #springone | @confluentinc Movies rated-movies Schema Registry

Slide 45

Slide 45

Create a new table, persist it to the log Browser ratings rated-movies Ratings Service Movies TRANSACTION Webserver Order rawRequested rating Connect ratings ratings counts ratings sums KAFKA @gamussa | @ #springone | @confluentinc Movies rated-movies Schema Registry

Slide 46

Slide 46

Hydrate a materialized view Browser ratings Ratings Service an embedded database CDC Webserver Order rawRequested rating Connect ratings ratings counts ratings sums Movies rated-movies KAFKA @gamussa | @ #springone | @confluentinc Schema Registry

Slide 47

Slide 47

What did you learn today? • Streaming services improve on the traditional microservices pattern in a number of ways: • Decouple ecosystems for easier change • Evolve existing databases into event streams with Kafka Connect. • Build on asynchronicity first. Add synchronicity where needed. @gamussa | #springone | @confluentinc

Slide 48

Slide 48

What did you learn today? • Remove the need for circuit breakers or other “overload” patterns. • Quickly combine and operate on data from many different services. • Embrace an immutable log that can be replayed. • Keep many databases, in many independent services, in sync. • Safely manage the evolution of data with the schema registry. @gamussa | #springone | @confluentinc

Slide 49

Slide 49

Want to learn more? @gamussa | #springone | @confluentinc

Slide 50

Slide 50

https://gamov.dev/spring20

Slide 51

Slide 51

Learn Kafka. Start building with Apache Kafka at Confluent Developer. developer.confluent.io Watch full version https://gamov.dev/developer

Slide 52

Slide 52

@gamussa | #springone | @confluentinc