I can see that RX is good for Android and for UI event handling. I'm struggling to see what benefits RX provides on the back-end.
Was RX Java designed for back-end processing, or has this concept been taken too far?
Moreover, RxJava is considered one of the most fruitful methods for enabling Reactive Programming in Android development. As we'll see below, the result is simplified implementation of concurrency and the asynchronous tasks inherent in mobile programming.
RxJava is a JVM library that uses observable sequences to perform asynchronous and event-based programming. Its primary building blocks are triple O's, which stand for Operator, Observer, and Observables. And we use them to complete asynchronous tasks in our project. It greatly simplifies multithreading in our project.
features. Coroutines will eventually be as mature as RxJava, but RxJava is never going to be able to integrate some of coroutines' best features. For our part, Trello Android is going to start slowly adopting coroutines as a replacement for RxJava.
Reactive programming is a design approach that uses asynchronous programming logic to handle real-time adjustments to typically static information. It provides an efficient mechanism — the use of automated data streams — for handling content modifications in response to user inquiries.
Actually, RxJava was firstly implemented to tackle server-side problems. Reactive extensions originated from .NET world and were ported to Java for their back-end by Netflix. RxJava became a thing on server-side Java programming years before adoption on Android.
Back then, asynchronous and non-blocking processing proved to greatly enhance server performance. One could use callbacks to achieve this, but callbacks doesn't compose well and lead to callback hell. RxJava with it's functional call chaining style offered a (good) solution and started to see adoption.
Then it spread to Android to deal with network calls or UI events. While I use and enjoy it on Android, I always found RxJava to be less at home in Android than in server. Because of the general design conceptually closer from other servers technologies IMHO, even if I know reactive extensions were used on client side from the beginning in .NET world. But also because RxJava usage in Android have it's flaw. You could easily leak Context
if you don't track your subscriptions. And you have to add .observeOn(AndroidSchedulers.mainThread())
nearly everywhere, that you forget from time to time and lead to crash. I bet it's the reasons who lead Android team to have their own take on the Observer pattern with Livedata on Architecture components.
Besides solving callback hell, RxJava offer to developer:
All in one, RxJava is a great fit for back-end processing, even more than in Android IMHO. You could find more on why Netflix implemented reactive extensions in Java and what where the benefits for their back-end here.
As of saying if it's needed for a server-side engineer, I would say it's not required but knowing it would greatly enhance your toolbox. Nowadays the trend is more and more asynchronous, with more and more middle-ware, libraries and framework offering only asynchronous API. Couchbase Java database API is based on RxJava for example. Plus reactive extension are not only Java, you will be able to leverage this knowledge in most languages.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With