A ReadableStream can appear to have backpressure yet still consume unbounded memory. The usual culprit is an extracted controller: an event handler calls enqueue() whenever data arrives, independently of whether the consumer is ready. The queue grows even though the stream was designed around pulling data. section 10.4.2 section 10.6.2
Web Streams are the web platform’s promise-based, pull-oriented streaming API. ReadableStream produces chunks, WritableStream consumes them, and TransformStream connects the two roles. Unlike Node.js streams, which principally push chunks through events, a Web Stream’s underlying source supplies data through pull() when the runtime sees room in its queue. fetch() supplies Web Streams; the same API works across browsers, Node.js, Deno, and Cloudflare Workers. section 10.2 section 10.4
Backpressure works only if production responds to the available room:
- A controller’s desiredSize is positive while the queue has room, zero at capacity, and negative beyond it. The runtime stops calling pull() when desiredSize is not positive. section 10.4.2
- Set a highWaterMark through a queuing strategy. CountQueuingStrategy measures values; ByteQueuingStrategy measures bytes, which is more predictable for variable-sized typed-array chunks. section 10.4.2
- If data arrives as events, pause its source when desiredSize reaches zero, resume it from pull(), and clean it up from cancel(). Enqueuing directly from events without that coordination bypasses structural backpressure. section 10.4.2
function streamFromFeed(feed) {
return new ReadableStream({
start(controller) {
feed.on('message', (msg) => {
controller.enqueue(msg);
if (controller.desiredSize <= 0) feed.pause(); // #A
});
feed.on('close', () => controller.close());
},
pull() {
feed.resume(); // #B
},
cancel() { feed.destroy(); } // #C
});
}This feed adapter connects an independently arriving push source to the pull cycle: the event handler checks desiredSize, pull() resumes production, and cancel() destroys the feed. section 10.4.2
Prefer pipeTo() and pipeThrough() over manually forwarding chunks. They carry backpressure and errors through the pipeline and clean up resources. If an underlying source throws, its ReadableStream enters an errored state and later reads reject; a pipe’s failure also surfaces through its promise. Await that promise rather than leaving rejection handling to the runtime. Transforms add inbound and outbound buffers, so a manually wired stage that ignores backpressure can let queues accumulate upstream. section 10.6.1 section 10.6.2 section 10.8
The WHATWG Streams Standard specifies observable behavior, not an allocation strategy. Promise and scheduling costs therefore vary by runtime. In one Node.js v24 measurement, a ReadableStream–TransformStream–WritableStream pipeline allocated twenty-seven promises per 4 KB chunk; that figure is not a portable constant. The cost matters most when per-chunk work is small and synchronous, less when I/O dominates. Keep a pipeline in Web Streams when it starts with fetch(), convert models at application edges rather than repeatedly within a pipeline, and release processed chunks instead of retaining them. section 10.2 section 10.6.3 section 10.8 section 10.4.5

