Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hystrix Execution Patterns

I'm trying to wrap my head around Hystrix and after reading their docs, still have a question about its usage patterns.

For one, I don't understand the use case for when to use their Asynchronous execution vs. their Reactive execution. The only difference I can see is that Asynchronous execution is always non-blocking, whereas Reactive can either be blocking or non-blocking. So I guess my real question is:

  • What's the difference between Synchronous and Blocking Reactive execution?; and
  • What's the difference between Asynchronous and Non-Blocking Reactive execution?
like image 208
smeeb Avatar asked Nov 21 '14 16:11

smeeb


1 Answers

Let's assume you have wrapped two service calls A and B as a HystrixCommand. You now have three options:

use .execute(): pure synchronous call. You call the method and continue your program once the result has arrived. Your program's total execution time is the sum both calls. The main flow of your program is very linear.

use .queue(): receive a Future immediately for both commands. Both service calls are executed in parallel. Then use .get() to retrieve the results. These calls with block until the result is there. Your total execution time is faster than before: your execution time will be the length of the longest service call. Use this when you i.e. want to combine the results of the two services. The main flow of your program is still linear, although both calls are executed in parallel.

use .subscribe(): receive a Observable immediately for both commands. Both service calls are executed in parallel. Then use .subscribe() to register a call-back to act on the result once it is available. This is very useful if you don't want to combine the results and want to react independently on the results of service A and B once they arrive. The main flow of your program is no linear, but reactive: the flow of the program will continue inside the callback for each command.

I hope it helps.

like image 184
ahus1 Avatar answered Oct 18 '22 19:10

ahus1