What backpressure is and why it matters
coreintermediateBackpressure is any mechanism that stops a fast producer from writing work faster than a consumer can process it. Without one, the gap between the two rates has to live somewhere — usually an in-memory queue that grows until the process runs out of memory and crashes.
Think of it as
Picture a kitchen where the sink drains at a fixed rate and a tap fills it. If the tap runs faster than the drain, the water does not vanish — it rises. Backpressure is turning the tap down, or shutting it off, before the sink overflows, instead of hoping the drain will magically speed up on its own.
What we're doing: Show an unbounded in-memory queue growing without limit under a sustained producer/consumer rate mismatch.
- 1
- A plain list has no capacity limit — every append() succeeds regardless of how far behind the consumer already is.
- 8
- The consumer's rate is bound by an external dependency (the database), not by anything the producer can see.
- 11
- This is the core problem: nothing in this code path ever signals "slow down" back to the producer, so the gap only widens.
Why this works: Every message the producer writes while the consumer is behind sits in `queue` in memory. At 800 events/sec of net growth, an hour of sustained mismatch queues 2.88 million events with nothing bounding how large that list can get.
Assuming a queue that "hasn't crashed yet" means the system is keeping up
Wrong
Better
What you see: The service runs fine for hours or days, then the process is suddenly killed by an out-of-memory error with no warning in the logs beyond memory usage that, in hindsight, had been climbing the entire time — because nothing was bounding the queue or alerting on its depth.
Why: An in-memory queue with no capacity limit can absorb an arbitrarily large backlog right up until the process runs out of memory — there is no natural ceiling that forces a decision earlier, so the first sign of trouble is the crash itself, not a graceful degradation.
- No backpressure
- Producer writes at full rate no matter what
- Queue grows without a ceiling during the spike
- Memory usage climbs until the process is killed
- Messages already buffered are lost on crash
- With backpressure
- Producer is signaled to slow down or blocked
- Queue depth stays within a known bound
- Memory usage stays flat and predictable
- Producer, not the queue, absorbs the slowdown
The producer/consumer mismatch and its consequence without backpressure
Remember: Backpressure exists because a producer and consumer rarely process at the same rate, and the gap has to go somewhere. Without a bound on the queue, "somewhere" is process memory, and the failure looks like a sudden crash after a period of no visible warning.
See also: connection lifecycle and backpressure · decoupling with queues · queue concepts

