Loading...
โœ“

12-Hour Money-Back Guarantee

๐Ÿ“˜ Why Queues Are Not Backpressure

LLDCoding Article

๐Ÿ“˜ Why Queues Are Not Backpressure

3 Apr 20222 min read

Buffers hide overload. They donโ€™t fix it.

โ€œWe added a queue, so weโ€™re safe now.โ€
โ€” Famous last words before an outage.

1๏ธโƒฃ The Dangerous Misconception

Common belief โŒ

โ€œIf traffic spikes, just put a queue in front.โ€

Reality โœ…

A queue absorbs load, but does not reduce it.

It only delays the pain.

2๏ธโƒฃ What Backpressure Actually Means

Backpressure means slowing or stopping upstream producers when downstream is overloaded.

A queue does none of that by default.

3๏ธโƒฃ The Core Failure Mode

When arrival rate > processing rate:

ฮป (incoming) > ฮผ (processing)

Queue length grows without bound.

The queue becomes a memory leak with latency.

4๏ธโƒฃ Why Queues Make Tail Latency Worse

What happens over time:

  1. Requests wait longer

  2. Timeouts trigger

  3. Clients retry

  4. Load multiplies

  5. System collapses

Queues convert overload into retry storms.

5๏ธโƒฃ Code Example โ€” Fake Safety โŒ

const queue = [];

app.post("/work", (req, res) => {
  queue.push(req.body);
  res.send("Accepted");
});

Why This Is Dangerous

  • No bound

  • No rejection

  • No feedback to clients

6๏ธโƒฃ Bounded Queues โ‰  Backpressure (Still Not Enough)

if (queue.length > 10_000) {
  throw new Error("Queue Full");
}

Better, but still:

  • Clients already sent traffic

  • Latency still spikes

  • Retries still happen

7๏ธโƒฃ What Real Backpressure Looks Like

โœ… Upstream Throttling

let inFlight = 0;
const MAX = 100;

app.get("/data", async (req, res) => {
  if (inFlight >= MAX) {
    return res.status(429).send("Too Busy");
  }

  inFlight++;
  try {
    res.send(await process());
  } finally {
    inFlight--;
  }
});

Work is rejected early, not queued forever.

8๏ธโƒฃ When Queues Are Actually Useful

Queues are not evil โ€” just misunderstood.

Queues are good for:

โœ” Async work
โœ” Decoupling systems
โœ” Load smoothing
โœ” Event processing

Queues are bad for:

โŒ User-facing latency paths
โŒ Unlimited buffering
โŒ Failure containment

9๏ธโƒฃ The Hidden Cost of Queues

Cost Impact
Memory growth OOM
Latency Unbounded
Retries Amplified
Visibility Poor
Fairness Broken

1๏ธโƒฃ0๏ธโƒฃ Real-World Examples

Kafka

  • Backpressure via consumer lag

  • Producers must slow down

TCP

  • Window size

  • Sender adapts rate

HTTP

  • 429 / 503

  • Retry-After

The queue alone is never the control loop.