feat(backend): implement automatic worker scaling via queue backlog m…#363
Merged
EDOHWARES merged 2 commits intoEDOHWARES:mainfrom May 1, 2026
Merged
Conversation
|
@CNduka001 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
Owner
|
Nice implementation, lgtm! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR #260 Automatic Worker Scaling via Queue Backlog Metrics
Description
This pull request implements dynamic backend worker scaling based on Redis queue backlog metrics. It improves performance and resource utilization by ensuring that BullMQ processing threads scale elastically with the transaction load, directly resolving the requirements mapped out for handling queue backlogs effectively without requiring constant container recreations (minimizing cold starts).
Key Changes
src/worker/scaler.jsto dynamically instantiate and shut down BullMQWorkerobjects internally based on the total number of waiting jobs across all configured networks.GET /api/queue/metrics(viaqueue.routes.jsandqueue.controller.js) to expose key metricstotalWaitingandtotalActive. This allows integration with Kubernetes HPA via custom metrics adapters if cluster-level pod scaling is preferred.worker/queue.jsandworker/processor.jsby explicitly passinglazyConnect: trueandmaxRetriesPerRequest: null. This guarantees that queue evaluation won't block the main event loop if the Redis server goes offline or restarts.processor.jsby wrapping legacy missing services (email.service,discord.service) intry-catchblocks, preventing the worker application from crashing or failing to bootstrap if these optional plugins aren't present./docs/queue_scaling.mdoutlining internal behavior, threshold configurations (MAX_WORKER_REPLICAS,JOBS_PER_WORKER_THRESHOLD), and giving explicit instructions on how to wire it up with standard Kubernetes HPA definitions.__tests__/scaler.test.jsleveragingnode:testto guarantee scaling logic up/down boundaries, enforcing that worker generation never exceeds the configured ceiling.Acceptance Criteria Met
/docsfolder.Closes #260