What is backpressure and how do you handle a queue that keeps growing?
Backpressure means slowing or limiting producers when consumers cannot keep up. For a growing queue, add consumers, make processing faster, reject or throttle new work, and set limits so the queue cannot grow without bound.
Explain it simply
Picture water filling a tank faster than the outlet drains it. Eventually it overflows. A queue works the same way: if messages arrive faster than they are processed, the backlog and the wait time grow, and memory or disk eventually runs out.
Responses, roughly in order:
- Measure: watch queue depth and age of the oldest message, not only throughput.
- Scale consumers up (autoscale on lag), if the work can run in parallel.
- Fix the slow part: a slow database call or a downstream API.
- Apply backpressure: tell producers to slow down, return HTTP 429 or 503, or block the producer when the queue is full.
- Shed load: drop low-priority work, or sample.
- Prioritise: separate queues for urgent and bulk jobs.
- Bound the queue so failures are visible instead of hidden in an endless backlog.
An unbounded queue just converts overload into hours of latency.
Example
Email service: producers send 500 jobs per second, workers finish 300.
Backlog grows 200 per second = 12,000 per minute
Fix 1: raise workers from 3 to 6 (600/s capacity) -> queue drains
Fix 2: cap queue at 100,000 and return 429 beyond thatWhat to say in the interview
"Backpressure propagates overload back to the source instead of letting queues grow unbounded. I watch depth and oldest-message age, scale consumers, fix the bottleneck, and throttle or shed low-priority load. Bounded queues make overload visible."