Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Reactive programming and Hystrix fault tolerance by Max Myslyvtsev

664 views

Published on

Reactive programming is a new paradigm that provides asynchronous event-based flow control. Java implementation is called rxJava and is being developed by Netfix. They have also released Hystrix — a non-functional layer that provides fault tolerance and latency features which also exposes reactive API.

Published in: Technology
  • Be the first to comment

Reactive programming and Hystrix fault tolerance by Max Myslyvtsev

  1. 1. Reactive programming and Hystrix fault tolerance Max Myslyvtsev
  2. 2. Agenda • Reactive • Observables • Hystrix • How we use it 2
  3. 3. Reactive Initiate Call Wait Get Response Continue 3
  4. 4. When call is complete Reactive Initiate Call Get Response Continue Continue 4
  5. 5. When call is complete Reactive Initiate Call Get Response React Continue 5 Observer pattern
  6. 6. Why Reactive? • Event-driven applications • Easy dependency composition • Allows parallel execution
 
 6
  7. 7. Why Reactive? • Event-driven applications • Easy dependency composition • Allows parallel execution • No callback hell 7
  8. 8. rxJava Observable<T> Future<T> Iterable<T> 8
  9. 9. Observable onNext onComplete onError 9 Terminal
  10. 10. Observable Observer onNext onComplete onError Subscription unsubscribe Observable subscribe Work start stop emit X
  11. 11. Operations • Create • Modify (immutable) • Terminate 10
  12. 12. Creation Create Observer onNext onComplete onError Subscription unsubscribe Observable subscribe onSubscribe X
  13. 13. Item Creation Never Just Empty ErrorThrowable 11
  14. 14. Creation FromIterable FromFuture Factory Defer Range 1 2 3Start, Count 12
  15. 15. Transformation Map 13
  16. 16. Transformation FlatMap 14
  17. 17. Filtering FilterTake Skip 15
  18. 18. Combination Merge 16
  19. 19. Combination Concat 17
  20. 20. Combination Zip+ 18
  21. 21. Aggregation 21 3 4 Reduceyx x+y+ 10 19
  22. 22. Error Handling onErrorReturn 20
  23. 23. Error Handling onErrorResumeNext 21
  24. 24. Error Handling onErrorResumeNext 22
  25. 25. Source Observable Lift onNext onComplete onError New Observable onNext onComplete onError Operator 23
  26. 26. Termination BlockingObservable Single[OrDefault] First[OrDefault] Last[OrDefault] ToIterable ToBlocking Observable 24
  27. 27. Observable<List> Termination ToList BlockingObservable<List> Single[OrDefault] ToBlocking Observable 25
  28. 28. Temperature Cold • Lazy • Does not emit until subscribed • Whole sequence Hot • Eager • Emits regardless of subscriptions • Partial sequence 26
  29. 29. Scheduling Observable subscribeOn observeOn Schedulers Immediate Trampoline New Thread Computations IO From(Executor) Test 27
  30. 30. Immediate Unit of Work schedule Unit of Work Thread X
  31. 31. Trampoline Unit of Work schedule Unit of Work X Thread
  32. 32. New Thread Unit of Work schedule Unit of Work Thread 1 Thread 2 X
  33. 33. Computations / IO Unit of Work schedule Unit of Work Thread 1 Pool X
  34. 34. Test Scheduler Unit of Work schedule Unit of Work Thread 1 Virtual Thread X
  35. 35. Dependency Composition • Single Item Observables • Fork Join • If Then Else X
  36. 36. Fork Join Map Map Observable Observable Observable Observable Zip X
  37. 37. If Then Else Filter (If) Filter (Else) Observable Map Map Observable Merge X
  38. 38. Why Hystrix? • Latency • Fault-tolerance • Isolation 28
  39. 39. Command Hystrix Fragile Operation API Observable Future Sync Execute Remote Service Metrics Dashboard Configuration Fallback 29
  40. 40. How we use it 30 Server REST Resources Client Maven Plugin Generated Client Hystrix generate during build REST API RX API same API
  41. 41. References • http://reactivex.io/intro.html • https://github.com/ReactiveX/RxJava/wiki • https://gist.github.com/staltz/ 868e7e9bc2a7b8c1f754 • https://github.com/Netflix/Hystrix/wiki • https://github.com/mmyslyvtsev/rx-workshop 31

×