Backpressure Pattern
Slow producer; protect consumer.
Overview
Backpressure slows producers when consumers cannot keep up. Without it, an unbounded queue silently grows until memory exhausts and the consumer dies under a load it never had a chance to drain.
- Slow producer to protect consumer. The consumer signals demand; the producer respects it. Without the signal, the producer assumes infinite capacity.
- Bounded queues. Every queue has a size limit. Hitting the limit triggers a deliberate policy: drop, block, or shed.
- Reactive Streams or equivalent. Demand-driven flow is the modern shape. Push-based pipelines are how OOM happens.
- Drop-or-block policy. Per channel, write down what happens at saturation. Drop is for telemetry; block is for ordered work; shed is for low-priority tenants.
The approach
Three properties make backpressure work in practice: bounded queues, demand-driven flow, and a documented overflow policy. None of the three is optional.
- Bounded queues. Every queue has a size limit. Unbounded queues are a contract to OOM eventually.
- Demand-driven flow. Reactive Streams, gRPC streaming, or Kafka consumer-paused-on-lag patterns. The consumer pulls; the producer waits.
- Per-consumer rate signal. Each consumer reports its current capacity. Producers throttle on the slowest consumer in the chain.
- Documented policy. Per channel, write down what happens at saturation. The next on-call inherits the decision rather than reverse-engineering it.
Why this compounds
Backpressure-discipline compounds across services. Each correctly-flowing channel removes one source of OOM in the system, and the patterns transfer to the next service the team builds.
- Resilience under load. Backpressure prevents OOM during traffic spikes; the consumer slows but stays up.
- Operational fit. Drop, block, and shed each fit different workloads. The discipline matches the policy to the workload, not the other way around.
- Predictable behaviour. Bounded queues produce predictable latency. Investigations get easier because the queue is not a black box.
- Knowledge transfer. The first backpressured channel takes effort. Each subsequent service inherits the patterns.