Essay Argues for a Better Streams API
A technical essay from Cloudflare argues that the current JavaScript Streams API is overdue for a redesign. The piece points out ergonomic pitfalls and inconsistencies that frustrate engineers, especially when streaming data between the browser, servers, and WebAssembly modules. The author calls for a new, "batteries-included" API that treats cross-environment composability as a first-class feature.
The current WHATWG Streams API, which underpins `fetch()` and is used by Node.js, Deno, and Bun, predates modern JavaScript features like async iteration. This legacy has resulted in an API with fundamental performance and usability issues that can't be easily fixed with incremental improvements. Performance benchmarks highlight significant overhead, largely due to the creation of a Promise for every chunk of data read. In server-side rendering with React, this can lead to a 12x performance gap compared to older Node.js streams, with Vercel measuring native Web Streams at 630 MB/s versus Node's `pipeline()` at ~7,900 MB/s for simple transformations. The author of the essay, James Snell, proposes a new API design centered on `AsyncIterable` as a core language primitive. This approach eliminates the need for `TransformStream` boilerplate and manual reader locking, treating streams as simple iterables which aligns better with modern JavaScript syntax and developer expectations. This alternative design has shown performance gains between 2x and 120x faster than the current Web Streams API in runtimes like Cloudflare Workers, Node.js, and browsers. The speedup comes not from clever optimizations, but from a fundamentally different design that avoids the Promise-per-chunk and object allocation overhead that burdens the existing standard. For developers working with WebAssembly, this matters because inefficient data streaming can be a bottleneck when moving data between JavaScript and Wasm modules. A more performant, lower-overhead streaming primitive would allow for more efficient integration, crucial for computation-heavy tasks that Wasm excels at. From an API design perspective, the debate highlights a key lesson for engineering leaders: APIs designed years ago may not suit contemporary programming paradigms. The complexity of the current Streams API, with concepts like BYOB (bring-your-own-buffer) readers being hard to implement correctly, hurts the developer experience. This conversation is being driven by engineers at companies like Cloudflare and Vercel who have encountered the limits of the current API while building large-scale, performance-sensitive systems. Their experience suggests that while standardization is crucial, the web platform also needs pathways to evolve its foundational primitives when they no longer meet the demands of modern applications.