Clients blasting 100 requests while our backend can safely handle only ~5 concurrent third-party calls.

February 21, 2026

Problem • Traffic spikes → workers multiply → race conditions and crashes • 3s third-party calls meant long inflight time and unpredictable throughput Approach • Centralize work with one BullMQ queue (fast enqueue, instant response to client) • Use Redis + Lua for atomic “check-and-lock” (an inflight counter) so only 5 jobs run across all workers • Optional secondary waiting queue + counter to hold and release excess work in a controlled way Why it works • Redis + Lua = atomic global coordination (no races) • Workers can scale horizontally without overwhelming the third party • Predictable throughput, graceful spikes, faster client-facing responses Result

  • No race conditions
  • Stable memory/CPU usage (no crashy worker storms)
  • Clear SLAs for third-party calls

Comments (0)