Skip to content

Backpressure

Category: Communication · Status: stub · Lessons: chapter 05, Message passing (planned)

One line: Letting a slow consumer slow its producers down — by making sends wait or fail — instead of letting unprocessed work pile up without limit.

Also called: flow control.

How it connects

flowchart LR
  n_backpressure["Backpressure"]
  n_bounded_channel["Buffered and bounded channels"]
  n_backpressure -->|uses| n_bounded_channel
  classDef center stroke-width:3px
  class n_backpressure center
  classDef outside stroke-dasharray: 4 3
  class n_bounded_channel outside

In each language

Rust a bounded sync_channel: send blocks until the buffer has room
Go a buffered channel: a send proceeds without blocking only while the buffer is not full (spec ↗)
Java Flow, the reactive-streams interfaces: a subscriber asks for items with request(n), a simple form of flow control
Python StreamWriter.drain: once the write buffer reaches the high watermark, it blocks until the buffer drains to the low watermark
C# BoundedChannelFullMode.Wait, the default for a bounded channel: WriteAsync waits for space
JavaScript streams ↗ compare their queue with a high water mark and report desiredSize; in Node, write() returns false until a 'drain' event (guide ↗)
Kotlin BufferOverflow.SUSPEND: the sender suspends while the buffer is full
The operating system a full pipe ↗ blocks the writing process until enough has been read to make room

Where to read more