Skip to content
Preptima
mediumConceptCodingMidSenior

Why would you stream a large file rather than read it into memory, and what is backpressure?

Node.js stream backpressure prevents a fast producer from filling memory while a slow consumer catches up. The core signal is write() returning false and the producer waiting for drain before sending more.

4 min readUpdated 2026-08-15

Answer

Short answer

Respect backpressure by pausing writes when write() returns false, waiting for drain, or using pipeline() so Node coordinates reads, writes, errors and cleanup. Ignoring it turns slow downstream I/O into memory growth.

Use streams as the boundary in the explanation: data is not being copied magically, it is being pulled or pushed through a contract with explicit flow control. A strong streams answer names where buffering happens and why ignoring that boundary turns a fast producer into a memory problem.

Was this answer helpful?

Likely follow-ups

  • What does `writable.write()` return, and what happens if you ignore it?
  • Why is `pipeline` preferred over `pipe` for anything that can fail?
  • Your stream processes JSON lines. How do you handle a record split across two chunks?
  • Where does an async iterator fit compared with the stream API?

Related questions

Further reading