Event-sourced system
through Reactive Streams
Workshop
Agenda
• 18:30 presentation introduction
• 19:00 exercise project reactor intro
• 19:30 short break
• 19:40 presentation event-sourcing
• 19:50 workshop
• 21:00 Closing & Networking
Reactive programming Belgium
R be
Reactive Programming Belgium
Your non-blocking resource in a reactive world
“We believe that RP is a good fit for
the challenges that
current applications/architectures entail”
Reactive Programming Belgium
Your non-blocking resource in a reactive world
• Research
• Share
• Blog
http://www.reactiveprogramming.be
• Meetups
https://www.meetup.com/Reactive-Programming-Belgium/
• Presentations
• ...
Reactive Programming Belgium
Your non-blocking resource in a reactive world
• Want to help?
• Writing articles (blog)
• Ideas/speakers/presenting…
• Prepare workshops
• Ad-hoc experiments
• ...
Reactive Programming Belgium
Your non-blocking resource in a reactive world
• Workshop :
‘Event-sourced system through Reactive Streams’
Reactive programming
Reactive programming
Applications today
• Applications today
• Increased magnitude of scale
• Big data (IoT, devices, …)
• Realtime
• Ex. Flight recorder
1 sec of flight = 1.5 TB of data
• Re-think the way we create applications
Reactive programming
Origin
• Origin @ Microsoft
• Erik Meijer
• Reactive programming framework (Reactive Extensions) for .NET
Reactive programming
Yet another programming model?
• Reactive
Something that responds to stimuli and actions
• Reactive Programming
• Rehashed programming model that emphasizes on scalability & response
• A way to build a scalable architecture that’s resilient and quick to react to
stimuli
• Ex. spreadsheet
Reactive programming
Data pipeline
• CRUD
• database -> function/process -> database
• Data pipeline
• data -> function -> data -> function -> data
• Data transformation instead of data manipulation
Reactive programming
Programming model – Reactive Streams
• Publisher (emit data)
• Subscriber (receive data)
• Subscription (~ session / context info)
• Processor
Flux.range(1, 10)
.filter(i -> isEven(i))
.map(i -> i * 2)
.subscribe(System.out::println);
Project reactor
Reactive programming
Programming model – Reactive Streams
• Publisher
onComplete()
onError()
next()
Reactive programming
Programming model – Reactive Streams
• Backpressure
Reactive programming
Programming model – Reactive Streams
• Java 9 Reactive Streams
• API (Publisher, Subscriber, Subscription, Processor)
= Reactive streams spec
• Frameworks/implementations
• RxJava (Netflix), project reactor, Akka-Streams, …
• RxJava 2
• Observable vs. Flowable >> both Publishers
• Project reactor
• Mono (0 - 1), flux (0 ..) >> both Publishers
• Reactive toolkit
• Vert.x
Reactive system
Reactive System
Reactive manifesto
• Elastic
• Message-driven
• Responsive
• Resilience
• Failure = first-class citizen
Reactive System
1 JVM
JVM
data -> function -> data -> function -> data
JVM
Reactive System
Distributed system
JVM
data -> data -> function -> data -> data-> function -> data
JVM
JVM JVM
JVM JVM
Reactive System
Distributed system
• Between jvm's
• http (spring webclient)
• gRPC, RSocket
• Messaging
• Between jvm & database
• non-sql vs sql
• Between jvm & UI
• RxJS
Project reactor
Project reactor
Flux & mono
• Flux = Publisher <0 .. N>
• Mono = Publisher <0 – 1>
Project reactor
Getting started
• Exercises
• Publisher / subscriber
• onComplete
• Error handling
• Backpressure
Project reactor
Getting started
• https://github.com/vanseverk/projectreactorintro
• IDE
• IntelliJ : mark ‘test’ folder as ‘test sources root’
• TODO 01 – 06
• Extra (backpressure)
• TODO 07 - 08
Event sourcing
Event Sourcing
Intro
• Persist events instead of domain objects
• Immutable event-log
• Replaying events can help development, debugging
• No need to lock DB tables
• Can be a perfect fit in event-driven architectures
• Can be designed to handle temporary partitioning
• Microservices handle (or replay) events and store what they require
• Eventual consistency
• Reactive Programming + Events -> Reactive Event Streaming
Event Sourcing
Intro
• Introducting: NATS
• https://nats.io/
• High performance messaging system for cloud native applications, IoT
messaging, and microservices architectures
• High performance, lightweight, many extensions
Event Sourcing
Intro
• Introducing: NATS Streaming
• Event Sourcing + Streaming including replay from time or sequence number
• Durable subscriptions for transient clients
• Persistent/guaranteed (at least once) message delivery
• Pub/Sub ; Request/Reply; Queueing to share work
Workshop
Reactive system: measurements
Architecture
Reactive system: measurements
Practical
• https://github.com/vanseverk/anomalydetection-nats
• 2 branches
• master = exercise (TODO)
• solution
• workshop.pdf
Workshop: Event-sourced system through Reactive Streams

Workshop: Event-sourced system through Reactive Streams