NODEJS Contents

Backpressure: The Real Reason Your Server Slows Down

Backpressure is how Node prevents memory blowups by slowing producers when consumers cannot keep up; you must respect it in streaming systems.

On this page

Understanding Backpressure

Backpressure is the mechanism that prevents writable streams from being overwhelmed by faster readable streams. Without it, memory usage grows uncontrollably.

highWaterMark Tuning

The highWaterMark option defines buffer limits. Proper tuning improves throughput in file servers and HTTP proxies.

Real-World Impact

Ignoring backpressure leads to container OOM crashes and degraded performance under load. Production systems must respect stream.write() return values and wait for the drain event.

if (!writable.write(chunk)) {
  await once(writable, 'drain');
}

Architectural Insight

Backpressure becomes critical in upload gateways, streaming APIs, and large-scale data ingestion services.