Backpressure: Signaling Upstream to Slow Down
Load Shedding vs Backpressure
Load shedding drops excess work. Backpressure slows upstream producers. Shedding discards data; backpressure preserves it by controlling flow. A queue with shedding drops messages when full. The same queue with backpressure tells producers to stop until consumers catch up. Shedding works when data loss is acceptable (telemetry). Backpressure is necessary when every message matters (financial transactions).
Backpressure Propagation
Backpressure must propagate through the entire chain. If Service C is slow, it signals B to slow down, B signals A, and clients receive 429 Too Many Requests with Retry-After headers. Without propagation, pressure accumulates in the middle, causing fragile components to fail.
Bounded Queues
The critical implementation detail is bounded queues. Unbounded queues hide backpressure by growing until memory exhausts causing OOM (Out of Memory) crashes. A bounded queue with 1000 items capacity forces blocking when full, naturally slowing the pipeline. Size for 2-5 seconds of burst capacity at expected throughput.
Implementation Mechanisms
HTTP services signal via 429 with Retry-After. Kafka lets consumers control read rate. TCP provides backpressure through window sizing. Credit based flow control grants producers permission to send: consumer grants 100 credits, each message consumes one, at zero credits producers wait.