Member-only story
Does the front-end need to care about back pressure?
What is back pressure?
Backpressure refers to a solution when the speed between producers and consumers does not match. If the speed of the producer is greater than that of the consumer, the consumer will be overwhelmed by the producer. At this time, a mechanism is needed to limit the speed of the producer, and this mechanism is called backpressure.
Perhaps some friends still don’t understand what back pressure is. Let’s take two examples to explain. One example is file reading and writing.
Assuming the reading speed is 150M/s and the writing speed is 100M/s, we can see that the reading speed is 50M/s faster than the writing speed. At this time, we must cache 50M of data per second for writing. However, if the cached data exceeds the memory size, OOM will occur. At this time, a mechanism is needed to limit the reading speed, which is backpressure.
In another scenario, let’s take a front-end related example, UI rendering. Assuming we have the output of a WebSocket that emits 20,000 events per second, we need to render these events onto the page. However, our page can only render 10,000 events per second. At this time, the problem shown in the following figure will occur.