← CodeClarityLab Home
Browse by Category
+ added · updated 7d
← Back to glossary

Backpressure

messaging Intermediate

TL;DR

Backpressure signals upstream producers to slow down when downstream consumers can't keep up — preventing queue overflow, memory exhaustion, and system collapse under load.

Explanation

Without backpressure: fast producer + slow consumer → queue grows indefinitely → OOM or unbounded latency. Backpressure strategies: (1) Block producer (synchronous — producer waits until consumer is ready). (2) Drop messages (circuit breaker — shed load). (3) Buffer with size limit (bounded queue — producer blocks or errors when full). (4) Rate limiting producer. (5) Signal via protocol (TCP flow control, Reactive Streams, gRPC flow control). In PHP: Redis list maxlength, queue bounded size, Swoole channel with capacity, HTTP 429 Too Many Requests. ReactiveX / RxPHP: Observable with backpressure operators.

Common Misconception

Unlimited queue size is safer — an unbounded queue causes OOM and system collapse. A bounded queue with explicit backpressure is safer.

Why It Matters

Without backpressure, a slow consumer causes unbounded queue growth that takes down the entire system — backpressure is the feedback mechanism that keeps systems stable under load.

Common Mistakes

  • Infinite queue — hides the problem until OOM.
  • No backpressure to HTTP clients — API accepts more than it can process.
  • Blocking the event loop with backpressure — use async/non-blocking where possible.

Code Examples

✗ Vulnerable
// Unbounded Redis list — can grow until OOM:
$redis->rpush('jobs', $job); // No limit
✓ Fixed
// Bounded with backpressure:
$len = $redis->llen('jobs');
if ($len >= 10000) {
    throw new ServiceUnavailableException('Queue full — apply backpressure');
    // HTTP 503 to caller — let them retry
}
$redis->rpush('jobs', $job);

Added 23 Mar 2026
Views 30
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
0 pings W 0 pings T 0 pings F 2 pings S 0 pings S 1 ping M 0 pings T 0 pings W 0 pings T 0 pings F 0 pings S 0 pings S 1 ping M 0 pings T 1 ping W 0 pings T 1 ping F 1 ping S 0 pings S 0 pings M 0 pings T 0 pings W 0 pings T 0 pings F 1 ping S 0 pings S 0 pings M 0 pings T 0 pings W 0 pings T
No pings yet today
No pings yesterday
Perplexity 8 Amazonbot 7 Google 4 Unknown AI 2
crawler 20 crawler_json 1
DEV INTEL Tools & Severity
🟠 High ⚙ Fix effort: Medium
⚡ Quick Fix
Set bounded queue size. Return 503 or block producer when full. Monitor queue depth. Add consumer scaling when depth exceeds threshold.
📦 Applies To
web cli queue-worker
🔗 Prerequisites
🔍 Detection Hints
rpush|queue.*push
Auto-detectable: ✗ No
⚠ Related Problems
🤖 AI Agent
Confidence: Low False Positives: High ✗ Manual fix Fix: Medium Context: File
CWE-400 CWE-770

✓ schema.org compliant