Handling backpressure

By default, writable streams have a high watermark of 16,384 bytes (16 KB). If the limit is met, the writable stream will indicate that this is the case and it's up to the stream consumer to stop writing until the stream's buffer has cleared. However, even if the high watermark is exceeded, a stream can still be written to. This is how memory leaks can form.

When a writable (or transform) stream is receiving more data than it's able to process in a given time frame, a backpressure strategy is required to prevent the memory from continually growing until the process begins to slow down and eventually crash.

When we use the pipe method (including when used indirectly via pump), the backpressure is respected by default. ...

Get Node Cookbook - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.