Skip to content

Backpressure

Backpressure adjusts incoming data to the receiver’s processing capacity through signals to slow down or pause.

Software architecture

Backpressure is feedback from a busy receiver asking an upstream data source to send less data or pause. It lets a processing stage adjust incoming flow to its capacity.

In a fictional import, the source reads 120 records per second while the database processes 40. With constant rates and no discarded records, the backlog grows by 80 records per second. A larger buffer postpones the problem. Backpressure makes the source read more slowly or pause until processing catches up.

Passing a pause signal upstream

On a functioning Node.js writable stream, a false return value from .write() signals a pause before sending more chunks. The chunk already passed in is not sent again for that reason. More chunks can follow after drain; errors and closed streams need separate handling. The buffer threshold highWaterMark is not a hard limit on total memory use.

The signal helps only if upstream stages respect it and bound their own buffers. If the source cannot be slowed, the application also needs bounded admission and a defined overload response. Rate limiting sets an allowed request rate; backpressure responds to receiving capacity within the data flow.

Sources