O slideshow foi denunciado.
Utilizamos seu perfil e dados de atividades no LinkedIn para personalizar e exibir anúncios mais relevantes. Altere suas preferências de anúncios quando desejar.
Reactive Programming with RxJava
for Faster Big Data
Michael Nitschinger
©2015 Couchbase Inc.
 New challenges need new solutions
 Modern applications need to
 React to user load
 React to fai...
©2015 Couchbase Inc.
Detour: Java Client Architecture
3
©2015 Couchbase Inc.
Detour: Smart Batching
Source: http://mechanical-sympathy.blogspot.co.at/2011/10/smart-batching.html
4
©2015 Couchbase Inc.
Detour: Smart Batching
Source: http://mechanical-sympathy.blogspot.co.at/2011/10/smart-batching.html
5
RxJava
A Gentle Introduction
©2015 Couchbase Inc.
 Java implementation for Reactive Extensions
https://github.com/ReactiveX
 A library to compose asy...
©2015 Couchbase Inc.
 Observables are the duals of Iterables
 They describe both Latency and Error side effects.
RxJava:...
©2015 Couchbase Inc.
Consuming Observables
9
 The Observer subscribes
and receives events.
 A cold Observable
starts whe...
©2015 Couchbase Inc.
RxJava: Creating Observables
just
10
©2015 Couchbase Inc.
RxJava: Creating Observables
11
©2015 Couchbase Inc.
RxJava: Creating Observables
12
©2015 Couchbase Inc.
RxJava: Creating Observables
13
©2015 Couchbase Inc.
RxJava: Creating Observables
14
©2015 Couchbase Inc.
RxJava: Creating Observables
15
©2015 Couchbase Inc.
RxJava:Transforming Observables
16
©2015 Couchbase Inc.
RxJava:Transforming Observables
17
©2015 Couchbase Inc.
RxJava:Transforming Observables
18
©2015 Couchbase Inc.
RxJava:Transforming Observables
19
©2015 Couchbase Inc.
RxJava:Transforming Observables
20
©2015 Couchbase Inc.
RxJava:Transforming Observables
21
©2015 Couchbase Inc.
RxJava:Transforming Observables
22
©2015 Couchbase Inc.
RxJava:Transforming Observables
23
©2015 Couchbase Inc.
RxJava:Transforming Observables
24
©2015 Couchbase Inc.
RxJava: Filtering Observables
25
©2015 Couchbase Inc.
RxJava: Filtering Observables
26
©2015 Couchbase Inc.
RxJava: Filtering Observables
27
©2015 Couchbase Inc.
RxJava: Filtering Observables
28
Error Handling
with RxJava
©2015 Couchbase Inc.
 Resiliency is key
 Things will go wrong, so better plan for it
 Do not aim for QA, aim for produc...
©2015 Couchbase Inc.
Timeouts
31
 The network is unreliable
 Servers fail
 The SDK contains bugs
 Always specify timeo...
©2015 Couchbase Inc.
Timeouts: Simple
32
©2015 Couchbase Inc.
Timeouts: Synchronous API
33
©2015 Couchbase Inc.
Timeouts: Complex Example
34
©2015 Couchbase Inc.
Coordinated Retry
35
 Fail fast
 Don’t let your system get stuck
 Shed load with backpressure
 Re...
©2015 Couchbase Inc.
Coordinated Retry: Fallback
36
©2015 Couchbase Inc.
Coordinated Retry with Delay
37
©2015 Couchbase Inc.
More Patterns
38
 Circuit Breaker (https://github.com/Netflix/Hystrix)
 Closed if everything okay
...
Thank you.
Próximos SlideShares
Carregando em…5
×

Couchbase Live Europe 2015: Reactive Programming with RxJava for Big Data Querying with N1QL

621 visualizações

Publicada em

Go reactive with RxJava in Couchbase Server.

Presented by: Michael Nitschinger, Couchbase

Publicada em: Software
  • Seja o primeiro a comentar

Couchbase Live Europe 2015: Reactive Programming with RxJava for Big Data Querying with N1QL

  1. 1. Reactive Programming with RxJava for Faster Big Data Michael Nitschinger
  2. 2. ©2015 Couchbase Inc.  New challenges need new solutions  Modern applications need to  React to user load  React to failure  Be responsive under load and failure  Decoupled, event-driven architectures are the foundation.  Resources need to be utilized as best as possible.  Waiting for IO is bad. Why Reactive? 2
  3. 3. ©2015 Couchbase Inc. Detour: Java Client Architecture 3
  4. 4. ©2015 Couchbase Inc. Detour: Smart Batching Source: http://mechanical-sympathy.blogspot.co.at/2011/10/smart-batching.html 4
  5. 5. ©2015 Couchbase Inc. Detour: Smart Batching Source: http://mechanical-sympathy.blogspot.co.at/2011/10/smart-batching.html 5
  6. 6. RxJava A Gentle Introduction
  7. 7. ©2015 Couchbase Inc.  Java implementation for Reactive Extensions https://github.com/ReactiveX  A library to compose asynchronous and event-driven programs through observable sequences. RxJava: Introduction single multiple sync T Iterable<T> async Future<T> Observable<T> 7
  8. 8. ©2015 Couchbase Inc.  Observables are the duals of Iterables  They describe both Latency and Error side effects. RxJava: Introduction event Iterable<T> (pull) Observable<T> (push) data retrieval T next() onNext(T) error discovery throws Exception onError(Exception) completion returns onCompleted() 8
  9. 9. ©2015 Couchbase Inc. Consuming Observables 9  The Observer subscribes and receives events.  A cold Observable starts when subscribed.  onNext can be called 0..N times
  10. 10. ©2015 Couchbase Inc. RxJava: Creating Observables just 10
  11. 11. ©2015 Couchbase Inc. RxJava: Creating Observables 11
  12. 12. ©2015 Couchbase Inc. RxJava: Creating Observables 12
  13. 13. ©2015 Couchbase Inc. RxJava: Creating Observables 13
  14. 14. ©2015 Couchbase Inc. RxJava: Creating Observables 14
  15. 15. ©2015 Couchbase Inc. RxJava: Creating Observables 15
  16. 16. ©2015 Couchbase Inc. RxJava:Transforming Observables 16
  17. 17. ©2015 Couchbase Inc. RxJava:Transforming Observables 17
  18. 18. ©2015 Couchbase Inc. RxJava:Transforming Observables 18
  19. 19. ©2015 Couchbase Inc. RxJava:Transforming Observables 19
  20. 20. ©2015 Couchbase Inc. RxJava:Transforming Observables 20
  21. 21. ©2015 Couchbase Inc. RxJava:Transforming Observables 21
  22. 22. ©2015 Couchbase Inc. RxJava:Transforming Observables 22
  23. 23. ©2015 Couchbase Inc. RxJava:Transforming Observables 23
  24. 24. ©2015 Couchbase Inc. RxJava:Transforming Observables 24
  25. 25. ©2015 Couchbase Inc. RxJava: Filtering Observables 25
  26. 26. ©2015 Couchbase Inc. RxJava: Filtering Observables 26
  27. 27. ©2015 Couchbase Inc. RxJava: Filtering Observables 27
  28. 28. ©2015 Couchbase Inc. RxJava: Filtering Observables 28
  29. 29. Error Handling with RxJava
  30. 30. ©2015 Couchbase Inc.  Resiliency is key  Things will go wrong, so better plan for it  Do not aim for QA, aim for production  Do not trust integration points  Treat the Database (SDK) as an integration point Reacting to Failure 30
  31. 31. ©2015 Couchbase Inc. Timeouts 31  The network is unreliable  Servers fail  The SDK contains bugs  Always specify timeouts and deal with them!  The synchronous wrapper defines them for you all the time.
  32. 32. ©2015 Couchbase Inc. Timeouts: Simple 32
  33. 33. ©2015 Couchbase Inc. Timeouts: Synchronous API 33
  34. 34. ©2015 Couchbase Inc. Timeouts: Complex Example 34
  35. 35. ©2015 Couchbase Inc. Coordinated Retry 35  Fail fast  Don’t let your system get stuck  Shed load with backpressure  Retry  immediately won’t help  either linear or exponential back-off necessary  have a strategy if retry also doesn’t work (Fallbacks!)
  36. 36. ©2015 Couchbase Inc. Coordinated Retry: Fallback 36
  37. 37. ©2015 Couchbase Inc. Coordinated Retry with Delay 37
  38. 38. ©2015 Couchbase Inc. More Patterns 38  Circuit Breaker (https://github.com/Netflix/Hystrix)  Closed if everything okay  Opens once the integration point breaks  Fail fast if open  Rechecking with half-open  Bulkheads  Contain errors into manageable compartments  Don’t let your ship sink!
  39. 39. Thank you.

×