31
Going Reactive Rob Harrop

Going Reactive: Building Better Microservices; rob harrop

Embed Size (px)

Citation preview

Page 1: Going Reactive: Building Better Microservices; rob harrop

Going ReactiveRob Harrop

Page 2: Going Reactive: Building Better Microservices; rob harrop

Who am I?

▸ CEO @ Skipjaq▸ ML-driven performance optimisation

▸ Co-founder of SpringSource

▸ Once upon a time I…▸ Contributed to Spring Framework

▸ Wrote a book about Spring

▸ Talked a lot about Spring

Page 3: Going Reactive: Building Better Microservices; rob harrop

Who am I?

▸ I’m on Twitter: ▸ @robertharrop

▸ I’m on Github/Gitlab: ▸ github.com/robharrop

▸ gitlab.com/rdh

▸ gitlab.com/skipjaq/hotspotmon

▸ I write about maths, modelling and performance ▸ https://robharrop.github.io

If you have questions after the session, {grab, tweet} me.

Page 4: Going Reactive: Building Better Microservices; rob harrop

Agenda

Page 5: Going Reactive: Building Better Microservices; rob harrop

Principles & Practice

Page 6: Going Reactive: Building Better Microservices; rob harrop

Why Reactive?

Page 7: Going Reactive: Building Better Microservices; rob harrop

Architecture is Fractal

Page 8: Going Reactive: Building Better Microservices; rob harrop

Reactive Systems

Page 9: Going Reactive: Building Better Microservices; rob harrop

ELKInflux Graphite

Publishers

Publish

Publishers

JVM JVM JVM

Systems as Streams

Hotspot MonSubscriber Publisher

Subscribe

Page 10: Going Reactive: Building Better Microservices; rob harrop

Reactive Subsystems

Page 11: Going Reactive: Building Better Microservices; rob harrop

JVM JVM

Subsystems as Streams

JVM Stat

Sampler

Clock

Repository

WebInflux

InfluxDB Browser

JVM

Page 12: Going Reactive: Building Better Microservices; rob harrop

Reactive Objects

Page 13: Going Reactive: Building Better Microservices; rob harrop

JVM

Total compiles

OSR compiles

100 83 62

12 8 5

Subscriber

Subscriber

Metrics as Streams

Page 14: Going Reactive: Building Better Microservices; rob harrop

JVM as Streams

Host JVM1359

JVM459

JVM1976

Page 15: Going Reactive: Building Better Microservices; rob harrop

Principles

Page 16: Going Reactive: Building Better Microservices; rob harrop

Reactive Manifesto

▸ Resilient▸ Responsive▸ Elastic▸ Message-driven

Page 17: Going Reactive: Building Better Microservices; rob harrop

Resilient

Page 18: Going Reactive: Building Better Microservices; rob harrop

Back Pressure

Total Compiles

Influx Publisher

Influx HTTP Client

q n

∞ m

When n>m we have back pressure - an upstream publisher is too quick for a downstream publisher

Page 19: Going Reactive: Building Better Microservices; rob harrop

Responsive

Page 20: Going Reactive: Building Better Microservices; rob harrop

Asynchrony

Publisher Subscriber

Q

U

E

UE

1

2

3

1

2

Page 21: Going Reactive: Building Better Microservices; rob harrop

Message-driven

Page 22: Going Reactive: Building Better Microservices; rob harrop

Reactive Streams

Page 23: Going Reactive: Building Better Microservices; rob harrop

public interface Publisher<T> {

public void subscribe(Subscriber<? super T> s);}

Page 24: Going Reactive: Building Better Microservices; rob harrop

public interface Subscriber<T> { public void onSubscribe(Subscription s);

public void onNext(T t);

public void onError(Throwable t);

public void onComplete();}

Page 25: Going Reactive: Building Better Microservices; rob harrop

public interface Subscription { public void request(long n);

public void cancel();}

Page 26: Going Reactive: Building Better Microservices; rob harrop

public interface Processor<T, R> extends Subscriber<T>, Publisher<R> {

}

Page 27: Going Reactive: Building Better Microservices; rob harrop

Project Reactor

▸ Reactive Streams defines a programming model

▸ Project Reactor provides an implementation of that model

▸ Flux<T> is a zero-to-many Publisher

▸ Mono<T> is a zero-or-one Publisher

▸ Reactor manages back pressure and asynch processing

Page 28: Going Reactive: Building Better Microservices; rob harrop

Practice

Page 29: Going Reactive: Building Better Microservices; rob harrop

Hotspotmon

Page 30: Going Reactive: Building Better Microservices; rob harrop

Summary

▸ Reactive is a fractal model

▸ Publishers capture outputs from systems

▸ Subscribers capture interaction with those outputs

▸ Async, isolation and capacity management are built-in

▸ Reactive Streams captures the core contracts of a Reactive system

▸ Project Reactor provides a sophisticated implementation of Reactive Streams

Page 31: Going Reactive: Building Better Microservices; rob harrop

Q&A