Reactive Streams

38
endava.com QUALITY. PRODUCTIVITY. INNOVATION. Reactive Streams By Dorin Cobzac

Transcript of Reactive Streams

Page 1: Reactive Streams

endava.com

QUALITY. PRODUCTIVITY. INNOVATION.

Reactive StreamsBy Dorin Cobzac

Page 2: Reactive Streams

2

2 QUALITY. PRODUCTIVITY. INNOVATION.

•Define the Problem•Describe the Solution•Conclude the Findings

Page 3: Reactive Streams

3

3 QUALITY. PRODUCTIVITY. INNOVATION.

•Define the Problem•Describe the Solution•Conclude the Findings

Page 4: Reactive Streams

4

4 QUALITY. PRODUCTIVITY. INNOVATION.

Every Minute:• Facebook users share nearly 2.5 million pieces of content.• Twitter users tweet nearly 300,000 times.• Instagram users post nearly 220,000 new photos.• Apple users download nearly 50,000 apps.• Email users send over 200 million messages.

HUGE amounts of Data

Page 5: Reactive Streams

5

5 QUALITY. PRODUCTIVITY. INNOVATION.

• … applications• … network nodes• … CPUs• … threads• … actors (actor systems)

Distributed between …

Page 6: Reactive Streams

6 QUALITY. PRODUCTIVITY. INNOVATION.

Distribution is trending

Page 7: Reactive Streams

7 QUALITY. PRODUCTIVITY. INNOVATION.

How to handling HUGE data streams across distributed systems?

Page 8: Reactive Streams

8

8 QUALITY. PRODUCTIVITY. INNOVATION.

Solutions?

Page 9: Reactive Streams

9 QUALITY. PRODUCTIVITY. INNOVATION.

• Making usual calls and wait for responses• Push to a Queue and risk losing messages• Use distributed queues

Page 10: Reactive Streams

10 QUALITY. PRODUCTIVITY. INNOVATION.

OR

Page 11: Reactive Streams

11

11 QUALITY. PRODUCTIVITY. INNOVATION.

Go Reactive

Page 12: Reactive Streams

12

12 QUALITY. PRODUCTIVITY. INNOVATION.

•Define the Problem•Describe the Solution• Conclude the Findings

Page 13: Reactive Streams

13

13 QUALITY. PRODUCTIVITY. INNOVATION.

•Define the Problem•Describe the Solution• Conclude the Findings

Page 14: Reactive Streams

14

14

What is a Stream?

QUALITY. PRODUCTIVITY. INNOVATION.

Page 15: Reactive Streams

15

15 QUALITY. PRODUCTIVITY. INNOVATION.

… but seriously, what is a Stream?

Page 16: Reactive Streams

16

16

• … may not have a start• … may not have an end• … doesn’t have a size• … its elements are retrieved/computed “on-the-spot”

A Stream is a Data source that …

QUALITY. PRODUCTIVITY. INNOVATION.

Page 17: Reactive Streams

17

17

Reactive Stream basics?

QUALITY. PRODUCTIVITY. INNOVATION.

Page 18: Reactive Streams

18

18

Data Flow: Fast Producer

QUALITY. PRODUCTIVITY. INNOVATION.

Page 19: Reactive Streams

19

19

Data Flow: Slow Producer

QUALITY. PRODUCTIVITY. INNOVATION.

Page 20: Reactive Streams

20

20

Data Flow: Self-regulating

QUALITY. PRODUCTIVITY. INNOVATION.

Automatically switches between being consumer and producer driven

Page 21: Reactive Streams

21

21

Data Flow: Asynchronous

QUALITY. PRODUCTIVITY. INNOVATION.

The communication between components is asynchronous!

Page 22: Reactive Streams

22

22

Data Flow: Back-pressure

QUALITY. PRODUCTIVITY. INNOVATION.

Page 23: Reactive Streams

23

23

Data Flow: Back-pressure

QUALITY. PRODUCTIVITY. INNOVATION.

Page 24: Reactive Streams

24

24

Stream Operations: Split

QUALITY. PRODUCTIVITY. INNOVATION.

Page 25: Reactive Streams

25

25

Stream Operations: Merge

QUALITY. PRODUCTIVITY. INNOVATION.

Page 26: Reactive Streams

26

26

Other Stream Operations

QUALITY. PRODUCTIVITY. INNOVATION.

• Filter certain elements from a stream• Transform one or more elements in a stream• Match certain elements based on some complex logic and/or order

Page 27: Reactive Streams

27

27

Reactive Streams working together

QUALITY. PRODUCTIVITY. INNOVATION.

Page 28: Reactive Streams

28

28 QUALITY. PRODUCTIVITY. INNOVATION.

•Define the Problem•Describe the Solution• Conclude the Findings

Page 29: Reactive Streams

29

29 QUALITY. PRODUCTIVITY. INNOVATION.

•Define the Problem•Describe the Solution• Conclude the Findings

Page 30: Reactive Streams

30

30

Reactive Streams: Advantages

QUALITY. PRODUCTIVITY. INNOVATION.

• Effective resource consumption• Flexibility• Inter-operability

Page 31: Reactive Streams

31

31

Reactive Streams: Caveat

QUALITY. PRODUCTIVITY. INNOVATION.

Go fully Reactive, or you’re not getting the full benefits

Page 32: Reactive Streams

32

32

Reactive Streams: Relevance

QUALITY. PRODUCTIVITY. INNOVATION.

Internet of Things is hereAre you ready?

Page 33: Reactive Streams

33

33 QUALITY. PRODUCTIVITY. INNOVATION.

Thank you!

Page 34: Reactive Streams

34 QUALITY. PRODUCTIVITY. INNOVATION.

Page 35: Reactive Streams

35

35

Reactive Stream Flavors

QUALITY. PRODUCTIVITY. INNOVATION.

1. Reactive Streams Specification v.1- Released on 30 April 2015- Contributions from Pivotal, Redhat, TypeSafe, Netflix- Includes a Technology Compatibility Kit- Only on JVM ecosystem (for now)

2. Reactive Extensions API- Multiple implementations (including .Net and Ruby)- A Netflix Original Production- Reactive Streams spec v.0.9 (kind-of)- Interops through RxJava Reactive Streams project

Page 36: Reactive Streams

36

36 QUALITY. PRODUCTIVITY. INNOVATION.

public interface Publisher<T> { public void subscribe(Subscriber<? super T> s);

} public interface Subscriber<T> {

public void onSubscribe(Subscription s); public void onNext(T t); public void onError(Throwable t); public void onComplete();

}

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

}

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

Reactive Streams Specification v.1

Page 37: Reactive Streams

37

37

Reactive Streams Specification v.1

QUALITY. PRODUCTIVITY. INNOVATION.

Page 38: Reactive Streams

38

38

Reactive Extensions API (short)

QUALITY. PRODUCTIVITY. INNOVATION.

public class Observable<T> { public static Observable<T> create(OnSubscriber<T> s);public Subscription<T> subscribe(Observer<? super T> subscriber);

} public interface Observer<T> {

public void onNext(T t); public void onError(Throwable t); public void onComplete();

}