What it is
Backpressure is any mechanism that lets a slower downstream component push back on a faster upstream one, so that work arrives no faster than it can be handled. The push-back can be waiting (the producer is blocked or only sends what it was granted) or refusing (the producer gets an error and must slow down, retry later or give up). Load shedding is the refusing half: deliberately rejecting work you cannot finish.
Why it exists
A queue decouples producers from consumers in time, but not in capacity. If messages arrive at 60 per second and are processed at 40, the backlog grows by 20 every second, forever. With an unbounded queue nothing fails at first: every publish succeeds, while the time from publish to processing climbs steadily. Eventually memory or disk runs out, messages expire, or the results arrive too late to matter, and by then the backlog takes a long time to drain. Backpressure makes the overload visible early and decides on purpose where the excess goes.
How it works
Bounded queues. Give every queue and buffer a limit. When it is full, a publish is rejected immediately (or blocks, see below). The limit also caps waiting: by Little's law, a full queue of N items drained at rate X holds a new item for about N ÷ X. A queue of 100 drained at 40 per second means at most about 2.5 s of waiting.
Blocking and credit-based flow control. If the producer can wait, it should. The simplest form is a blocking put on a bounded in-process buffer. Across a network, the receiver grants credit and the sender stays within it: TCP's receive window, HTTP/2 and gRPC flow-control windows, AMQP consumer prefetch, and Reactive Streams' request(n) all work this way. The pressure moves upstream hop by hop: the producer slows down, so its own callers wait or its own buffers fill.
Shedding at the edge. Pressure that travels upstream eventually reaches a component that cannot wait: a public client, a sensor, a partner's webhook. There the system must say no. A gateway or load balancer enforcing a rate limit (token bucket, leaky bucket) answers the excess with 429 Too Many Requests, ideally with Retry-After, before the request consumes any downstream resources. Overloaded services can also return 503 and shed lower-priority traffic first.
Signals for producers. Rejections only help if producers react: retry with exponential backoff and jitter, cap retries, and degrade (skip a non-essential step, batch more) instead of hammering. A producer that retries instantly turns load shedding into a retry storm.
Capacity. Backpressure keeps the system healthy during overload; it does not process the rejected work. For lasting load, add consumers or make each message cheaper, ideally with autoscaling on queue depth or message age, with the bounded queue and edge limit covering the minutes autoscaling takes to react.
When to use it
- Always: every queue, buffer, thread pool and connection pool should have an explicit bound and a defined behaviour when full.
- Flow control for internal pipelines where producers can safely wait (stream processing, batch imports, service-to-service streaming).
- Edge rate limiting and load shedding for public APIs, ingestion endpoints and anything exposed to traffic you do not control.
When not to
- Do not block producers that hold scarce resources while waiting (request threads, database transactions, locks): blocking there spreads the overload to unrelated work.
- Do not rely on blocking for public clients; they will time out and retry, adding load.
- Do not bound a queue so tightly that ordinary bursts are rejected; size it for the burst you want to absorb and the wait you can tolerate.
Trade-offs
| Choice | You gain | You pay |
|---|---|---|
| Unbounded queue | No rejections, simplest code | Unbounded latency and memory; overload discovered late |
| Bounded queue, reject when full | Bounded wait, early explicit signal | Rejected work; producers must handle errors |
| Blocking / credit-based flow control | No drops while every hop can wait | Pressure (and latency) moves upstream; risk of blocked threads |
| Rate limit at the edge | Cheapest rejection, protects everything behind it | Must pick limits; may reject when there was spare capacity |
| Larger buffer | Absorbs longer bursts | Longer worst-case wait; slower drain after overload |
| Autoscaling consumers | Removes sustained overload | Reacts in minutes; costs money; may overload the next dependency |
Alternatives
- Drop oldest / sample: for telemetry and real-time feeds, discard stale messages instead of rejecting new ones.
- Batching: let consumers process many messages per operation to raise throughput under load.
- Priority queues and load shedding by class: keep serving important traffic (checkout) while shedding the rest (recommendations).
- Graceful degradation: answer with less (cached or partial results) instead of nothing.
- Admission control based on latency: adaptive concurrency limits that lower the number of accepted requests when latency rises.
Failure modes
- Silent backlog: an unbounded queue grows for hours while every dashboard shows success; alerting on depth and the age of the oldest message catches it.
- Bufferbloat: buffers everywhere along the path each add waiting time, so total latency explodes long before anything rejects.
- Retry storms: producers retry rejections immediately and multiply the load.
- Blocked threads: a producer blocks inside a request handler; the thread pool fills and unrelated endpoints stall.
- Rejecting too deep: work is accepted at the edge, partly processed, and rejected three hops later, which wastes the work done so far.
- Slow drain: after the overload ends, a huge backlog takes a long time to clear, and all of it is stale.
In production
Give every queue, buffer and pool an explicit bound and document what happens when it is full. Alert on queue depth and on the age of the oldest message, not just on errors. Rate limit at the edge per client or tenant, return 429 with Retry-After, and make producers back off with jitter. Prefer flow control between internal services that can wait, but never block a request thread on it. Autoscale consumers on backlog or message age, and load test past saturation to see where the system sheds. For an unbounded backlog under a traffic surge, try the Queue Backlog scenario in the Failure Lab.
Common misconceptions
- "No errors means the system is coping." An unbounded queue reports success while latency grows without limit.
- "A bigger queue fixes overload." It only delays the moment it fills, and makes every message wait longer.
- "Backpressure means dropping messages." Dropping is one form; waiting (flow control) is the other. Both are deliberate.
- "Rate limiting and backpressure are the same." A rate limit is a fixed admission rule at one point; backpressure is a signal from downstream capacity that propagates upstream.
Interview angle
When a design has a queue or a high-volume ingestion path, interviewers ask "what happens when consumers fall behind?" A strong answer quantifies the gap ("60 in, 40 out, +20/s, 72,000 per hour"), bounds the queue, says where load is shed (429 at the gateway, per tenant), how producers react (backoff with jitter), how long accepted messages may wait (capacity ÷ throughput), and how capacity catches up (autoscaling on message age). Mentioning that blocking moves pressure upstream until something can say no shows you understand the whole chain.
Model assumptions
The simulation is a simplified model, not a benchmark. Producers publish at the stated rate (Poisson). Two workers (three from the capacity step on) with 4 slots each take about 200 ms per message (lognormal, cv 0.3), about 40 messages per second for two workers. The unbounded queue is a capacity of 100,000; the bounded queue holds 100 and rejects publishes immediately when full. The ingest gateway admits traffic with a token bucket (36 per second, burst 20; later 60 per second, burst 40) and rejects the rest at once. The engine cannot block a producer: the credit tokens are a scripted illustration, and their effect is modelled by lowering the producers' rate to about 36 per second. Message wait is measured from publish to acknowledgement. Latency percentiles (P50, P95, P99) are computed over the requests that succeeded in the last 5 simulated seconds: failed, rejected and timed-out requests are not in them and are counted in the Errors tile, which is always shown next to them. Rejecting or timing out the slowest requests therefore improves the percentiles while making the system less reliable, so read the two together. Numbers show behaviour and orders of magnitude only.