What does the term "backpressure" mean in Rxjava?
Asked Answered
R

3

28

I am a beginner of RxJava and I am curious about the meaning of "backpressure".

Does it mean that the producer puts pressure behind the consumer's back?

Or does it mean that consumers are putting pressure on producers? (Pressure in opposite direction)

Refectory answered 1/10, 2017 at 23:57 Comment(3)
The latter. The consumer need more time to process so it slows down the producer. Back pressure is generally a bad thing as it requires side-effects to implement and that can cause all sorts of logic issues. Without back pressure Rx is purely functional.Maturity
Thanks to you. There is one more question. It's not important ... I think that 'Inverse control' or 'Back signal' is more appropriate than 'Back-Pressure'. Why did people use the word 'pressure'? The sentence that a consumer are pressing the producer seems to be an overstatement.Refectory
I think the idea of "pressure" is that the producer is pushing on the consumer. So then "back pressure" is the consuming being able to push back on the producer.Maturity
D
26

RxJava 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.

Since it requires system resources to handle backpressure, you need to choose right backpressure strategy that suits your requirement.

More Info ref link

Detradetract answered 7/3, 2018 at 7:29 Comment(0)
K
8

Consider a situation where you have a huge amount of data , for eg. a sensor emits huge amount of data which is emitted at a high rate.
In such a scenario we need backpressuring , which in simple words is just a way to handle the items that can’t be processed.
Now in order to relieve this pressure we explicitly specify different backpressuring strategies like

  • Dropping (BackpressureStrategy.DROP) : This strategy drops items ,
    when it can't handle more than its capacity
  • Latest (BackpressureStrategy.LATEST) : If the downstream can't cope up with the flow of items, it stops emitting and waits till it becomes available again. It keeps dropping items , except the last one that arrived and sends the last one when the downstream is available.
  • Buffer (BackpressureStrategy.BUFFER) : Save the items in a buffer till they can be processed.

Demystifying RxJava Backpressure on Android at Uber Engineering

Keyhole answered 26/10, 2019 at 11:27 Comment(0)
V
7

I have read a lot about back-pressure but nothing satisfied me until I came across a post by Jonas (co-author of the reactive manifesto). I hope this will clarify your doubts regarding back-pressure.

When one component is struggling to keep-up, the system as a whole needs to respond in a sensible way. It is unacceptable for the component under stress to fail catastrophically or to drop messages in an uncontrolled fashion. Since it can’t cope and it can’t fail it should communicate the fact that it is under stress to upstream components and so get them to reduce the load. This back-pressure is an important feedback mechanism that allows systems to gracefully respond to load rather than collapse under it. The back-pressure may cascade all the way up to the user, at which point responsiveness may degrade, but this mechanism will ensure that the system is resilient under load, and will provide information that may allow the system itself to apply other resources to help distribute the load, see Elasticity.

Verbal answered 23/10, 2019 at 6:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.