Skip to content

feat(backend): implement BullMQ background worker queue for AI feedback (#317)#347

Open
Diwakar-odds wants to merge 1 commit into
Canopus-Labs:mainfrom
Diwakar-odds:feature/issue-317-bullmq
Open

feat(backend): implement BullMQ background worker queue for AI feedback (#317)#347
Diwakar-odds wants to merge 1 commit into
Canopus-Labs:mainfrom
Diwakar-odds:feature/issue-317-bullmq

Conversation

@Diwakar-odds

@Diwakar-odds Diwakar-odds commented Jul 5, 2026

Copy link
Copy Markdown

Resolves #317.

What is this PR doing?

This PR introduces BullMQ and IORedis as a background worker queue for processing Google Gemini API calls. This architectural shift prevents HTTP timeout errors on the main Express server by offloading heavy AI operations to a background queue. The API now returns an immediate jobId for the client to poll, allowing scalable asynchronous handling.

How was it implemented?

  1. Queue Setup: Configured a Redis connection and a BullMQ queue (ai-jobs) with exponential backoff retries.
  2. Worker Implementation: Extracted the core Gemini API interactions from the Express controllers and placed them in a dedicated BullMQ worker (aiWorker.js). The worker maps job names (like chat, generate-questions) to specific processor functions.
  3. Controller Refactoring: Updated the HTTP routes/controllers to enqueue tasks to BullMQ instead of awaiting Gemini synchronously. The API immediately returns HTTP 202 with a jobId.
  4. Status Polling: Introduced a new /api/jobs/:jobId endpoint to allow clients to poll for task completion.

Files Changed

  • backend/package.json & package-lock.json: Added bullmq and ioredis.
  • backend/config/queue.js (NEW): Initializes the ai-jobs queue and Redis connection.
  • backend/workers/aiWorker.js (NEW): Contains the BullMQ worker processing logic.
  • backend/controllers/aiController.js: Refactored generateInterviewQuestions, generateConceptExplanation, and generateInterviewTips to add jobs to the queue.
  • backend/routes/aiRoutes.js: Refactored /generate chat route to add jobs to the queue.
  • backend/routes/jobRoutes.js (NEW): Added GET endpoint for polling job status and results.
  • backend/server.js: Mounted /api/jobs router and required the background worker.

ECSoC26 Contribution Analysis

According to the ECSoC '26 points system, I request the maintainers to evaluate this PR based on the following:

  • Core Backend Architecture Work (Level 3 - 15 Points): This PR implements a significant architectural enhancement to the backend's core operations, introducing asynchronous job queueing with Redis and BullMQ, completely reshaping how API interactions are handled.
  • Admin Bonus Labels Request: This strongly fits the criteria for the good-backend (+50 XP) label as it solves a critical backend scalability issue (HTTP timeouts during long Gemini response times).

Please review and add the ECSoC26 label, and explicitly consider adding Level 3 and good-backend based on this analysis.

@Diwakar-odds

Copy link
Copy Markdown
Author

Hi maintainers, could you please review this PR?

ECSoC26 Contribution Analysis & Label Request:
Based on the official ECSoC26 points criteria, I request that this PR be considered for Level 3 (15 points) as it involves a significant refactor to the core backend architecture by integrating BullMQ and Redis for background job queueing. This fixes major scalability issues and HTTP timeouts. Furthermore, since this explicitly targets the backend's core operations, I request the good-backend (+50 XP) bonus label.

Please add the \ECSoC26\ label (if not automatically applied), along with \Level 3\ and \good-backend\ to accurately reflect the work done. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Backend/Arch] Implement a background worker queue for processing AI feedback

1 participant