Dev.Lib
arrow_backBack to Blogs
LEVEL_088.5June 27, 20261 min read

Backpressure handling

Concurrency & Streams

Producers must respect consumer speed — streams, SSE, WebSocket flood, rapid setState from socket.

Summary

Producers must respect consumer speed — streams, SSE, WebSocket flood, rapid setState from socket. Batch updates (startTransition, rAF throttle), drop/sample high-frequency events. Unbounded queues grow memory and INP.

Code example

const { readable, writable } = new TransformStream({
  transform(chunk, controller) {
    if (controller.desiredSize <= 0) return; // respect backpressure
    controller.enqueue(process(chunk));
  },
});

Key points

  • Producers must respect consumer speed — streams, SSE, WebSocket flood, rapid setState from socket.
  • Batch updates (startTransition, rAF throttle), drop/sample high-frequency events.
  • Unbounded queues grow memory and INP.

Further reading

Related concepts