advanced

Backpressure

Slow producers or shed work when consumers, streams, queues, or dependencies cannot keep up safely.

Backpressure signals that a downstream stage cannot keep up—slowing producers, shedding load, or rejecting work instead of buffering forever and increasing latency without bound.

| Mechanism | Example | |-----------|---------| | Bounded queue | Drop or reject when full | | HTTP 503 + Retry-After | Client backs off | | Stream `pause()` | Node readable waits for consumer | | Concurrency limit | Only N in-flight jobs |

					if (queue.length >= MAX) return res.status(503).send('overloaded');
				

Healthy systems **fail fast** under overload rather than accept infinite work. Pair backpressure with metrics on rejections and queue depth so operators see pressure before total collapse.

On interviews: difference from rate limiting; backpressure in streams; cascading failure without shedding; graceful degradation patterns.

Common pitfalls: unbounded in-memory buffers; retry storms after 503; no coordination between services on overload.

The trade-off is protecting tail latency versus dropped or delayed work.

Checklist:

  • Bound buffers at every stage.
  • Shed load with clear client signals.
  • Coordinate retries with jitter.
  • Test overload paths in load tests.