Reputation: 2906
Observable and Flowable interfaces seem to be identical. Why Flowable was introduced in RxJava 2.0? When should I prefer to use Flowable over Observable?
Upvotes: 36
Views: 11078
Reputation: 41638
As stated in the documentation:
A small regret about introducing backpressure in RxJava 0.x is that instead of having a separate base reactive class, the Observable itself was retrofitted. The main issue with backpressure is that many hot sources, such as UI events, can't be reasonably backpressured and cause unexpected
MissingBackpressureException
(i.e., beginners don't expect them).We try to remedy this situation in 2.x by having
io.reactivex.Observable
non-backpressured and the newio.reactivex.Flowable
be the backpressure-enabled base reactive class.
Use Observable
when you have relatively few items over time (<1000) and/or there's no risk of producer overflooding consumers and thus causing OOM.
Use Flowable
when you have relatively large amount of items and you need to carefully control how Producer
behaves in order to to avoid resource exhaustion and/or congestion.
Backpressure When you have an observable which emits items so fast that consumer can’t keep up with the flow leading to the existence of emitted but unconsumed items.
How unconsumed items, which are emitted by observables but not consumed by subscribers, are managed and controlled is what backpressure strategy deals with.
Upvotes: 54