What is backpressure in Node.js streams?
Answer
Backpressure is a mechanism in Node.js streams to prevent a fast readable source from overwhelming a slow writable destination. Without backpressure, data would pile up in memory until the process crashes with an out-of-memory error. The writable stream's write(chunk) method returns false when its internal buffer is full (exceeding the highWaterMark, default 16KB). The readable stream should pause (readable.pause()) at this signal and wait for the writable to emit the "drain" event before resuming. The pipe() method handles this automatically — it pauses the readable when the writable signals backpressure and resumes when it drains, making it the recommended approach for connecting streams. Manual backpressure management is needed when building custom Transform streams or implementing your own pipeline logic. Ignoring backpressure causes memory leaks in data-intensive applications like ETL pipelines and file processors.
Previous
What is the difference between cluster and Worker Threads?
Next
What is the difference between readFile and createReadStream?