# Backpressure: Keeping Fast Producers from Overwhelming Slow Consumers

Any pipeline where one stage can produce faster than the next can consume needs a plan. Interviewers like candidates who raise this before being asked.

## Symptoms without backpressure

Queues grow without limit, memory fills, latency climbs because every request waits behind a long queue, and eventually the slow stage crashes, taking the backlog with it.

## Strategies

1. **Bounded queues**: give every buffer a maximum size. When it is full, the producer must wait, drop, or fail fast.
2. **Blocking / pull-based flow**: the consumer asks for N items when it is ready (Reactive Streams `request(n)`, Kafka consumers pulling at their own pace, gRPC and HTTP/2 flow-control windows).
3. **Load shedding**: reject excess work early with 429 or 503 so the requests you do accept stay fast. Shed low-priority traffic first.
4. **Rate limiting at the edge**: token buckets per client so one caller can't flood the system.
5. **Buffer in a durable log**: put Kafka between stages so bursts are stored on disk and consumers catch up later, while you monitor consumer lag.
6. **Autoscale consumers** based on queue depth or lag, with a cap.

## Choosing

- Interactive APIs: fail fast and shed load; users would rather retry than wait 30 seconds.
- Analytics and logging: buffer durably and accept delay.
- Telemetry where only the latest value matters: drop old samples.

## Metrics to watch

Queue depth, consumer lag, time in queue, and rejection rate. A growing queue is the earliest warning.

Disclosure: I help build Linkjob AI (https://www.linkjob.ai/), an AI coding interview assistant.
