When a consumer is too slow, push back on the producer instead of letting everything pile up.
Back pressure is a way for a slow part of a system to push back on a fast part, instead of letting work pile up until something breaks.
Think of two machines joined by a pipe. The first one (the producer) puts work in. The second one (the consumer) takes work out and does it. If the consumer is slower, the pipe slowly fills up. What should happen when it is full?
If the answer is "keep accepting everything", the buffer grows, the delay for each new item grows, and eventually the process runs out of memory. This is the quiet danger of unbounded queues. Back pressure is the set of ideas that avoids it: limit the buffer, and tell the sender about the limit.
The bars are an illustrative comparison of risk, not measurements.
| Strategy | How it works | Good for | Watch out for |
|---|---|---|---|
| Unbounded buffer | Accept all, queue it | Small, short bursts you are sure about | Memory use, rising delay, crash |
| Bounded + drop (load shedding) | When full, discard new (or old) items | Work that can be skipped: metrics, video frames, best-effort tasks | Data loss, so decide what to drop |
| Bounded + block | When full, the producer waits, or gets 429/503 | Work that must not be lost | Producers must handle waiting or retries |
| Pull / credit-based | Consumer requests N items at a time | Streams with steady flow and clear ownership | Needs both sides to support the protocol |
| Form | Example |
|---|---|
| Network flow control | TCP window: the receiver tells the sender how much it can accept |
| HTTP status codes | 429 Too Many Requests and 503 Service Unavailable, often with a Retry-After header |
| Bounded queues | A thread pool with a small queue and a rejection policy |
| Prefetch / credits | A message consumer that takes only a few unacknowledged messages at a time |
| Reactive streams | A subscriber requests n items, and the publisher never sends more than requested |
Everything is accepted and queued. The queue has no limit, so memory is the only limit.
A simplified model with a simulated clock (no random numbers) and made-up round numbers, so treat it as illustrative. Each second the consumer works through the queue, then new items arrive, and whatever does not fit is handled by the strategy you chose.
| Term | Meaning in easy words |
|---|---|
| Producer | The part that creates work and sends it on |
| Consumer | The part that receives work and does it |
| Queue / buffer | A waiting line between producer and consumer |
| Bounded queue | A queue with a fixed maximum size |
| Unbounded queue | A queue with no size limit, so only memory limits it |
| Back pressure | A signal or rule that makes the producer slow down when the consumer is overloaded |
| Load shedding | Deliberately dropping some work so the rest can be done well |
| Flow control | Controlling how fast data is sent, as TCP does with its window |
| Consumer lag | How far behind the consumer is, in items or in time |
| Credit / demand | The number of items a consumer says it is ready to receive |
| 429 / 503 | HTTP status codes that mean 'too many requests' and 'service unavailable' |
| Choice | We gain | We lose |
|---|---|---|
| Small queue | Low delay and low memory use | Less room for bursts, so more rejections |
| Large queue | Absorbs bigger bursts | Long delays, and a bigger crash when it overflows |
| Drop when full | Fast and simple, protects the consumer | Lost work |
| Block when full | No lost work | Slowness moves to the producer and its callers |
| Reject early (429/503) | Fast, clear feedback to clients | Users see errors, so clients need retry logic |
| Pull / credits | Fine control, steady flow | More complex protocol on both sides |