1- Thread pool: Performance demands are always increasing.
Site performance is very important. A study was done on user behavior showing that:
2- The rise of microservice: Increase of distributed systems, where there are multiple integration points. A lot of interfaces: DB, 3rd party APIs, other services.
Embrace Reactive Applications. This word was made famous in Sept.2014 in the Reactive Manifesto.
ReactiveX is a combination of the best ideas from the Observer pattern, the Iterator pattern, and functional programming
4 principles in order to properly fulfill user demand. Being reactive is not a library or framework. It is a set of design principles that your app should meet.
1- Responsive. It should respond to user interaction asap. Whether it is http request, or button click etc. Amazon experimented with added 100ms to each interaction -> 1% decrease in sale
2- Resilient. Embrace Failure. Everything can break, so should guard against it. Independent things should fail independently.
3- Elastic (scalable)
4- Message-Driven. Free up resources with Async operations & non-blocking I/O
Now do all of this at ALL levels of your stack
Async is hard for humans! But One excellent tool is reactive streams.
Rx simplifies complex work. At the beginning it is challenging and complicated. But once you get the hang of it, becomes good.
An observable is like a promise ++. Observables are most powerful when wrapping an external input. An observable epushes down an items to the observers. Observables and subscribers operate on a scheduler.
Observable pattern is a core part of Rx.
Streams are composable. Don’t need to have subscribers all the time.
5 main functions that we usually use
Cold streams/observable: Finite data, on demand. only emits data on.subscribe
Hot observable: infinite data, as it’s ready. emits always data.
Asnychronous streams: can use ObserveOn and subscribeOn to run things in background
Stream interactions:
Flowable is an observable, with some extra apis that you can use.
Focus on Intra-Service operations, for JVM. Some popular libraries:
Observables are publishers at the end of the day.
The observable.zip method is interesting as it combine the emissions of multiple Observables together via a specified function and emit single items for each combination based on the results of this function