A production-grade background job processing system built with Node.js, BullMQ, Redis, and MongoDB. Supports priority queues, concurrent workers, exponential backoff retry, dead letter queuing, and a real-time monitoring dashboard.
Client → Express API → BullMQ Queue → Worker → MongoDB
↓ ↓
Redis (state) Job history
↓
Dead Letter Queue (on max retries)
| Layer | Technology |
|---|---|
| API | Node.js, Express |
| Queue | BullMQ |
| Cache/State | Redis |
| Database | MongoDB |
| Dashboard | Bull Board UI |
| Container | Docker |
| Tests | Jest, Supertest |
docker compose up -dApp runs at http://localhost:3000
1. Start Redis & MongoDB
docker compose up redis mongodb -d2. Install dependencies
npm install3. Configure environment
cp .env .env.local
# Edit .env.local if needed4. Start the API server
npm run dev5. Start the workers (separate terminal)
npm run workers| URL | Description |
|---|---|
http://localhost:3000 |
API root |
http://localhost:3000/health |
Health check |
http://localhost:3000/dashboard |
Bull Board UI |
http://localhost:3000/api/jobs |
Jobs API |
http://localhost:3000/api/jobs/metrics |
Queue metrics |
POST /api/jobs
Content-Type: application/json
{
"queueName": "email", // email | report | notification
"jobName": "send-welcome-email",
"data": {
"email": "user@example.com",
"firstName": "Alice"
},
"priority": "high", // high | medium | low
"maxAttempts": 3,
"scheduledFor": "2024-12-01T09:00:00Z" // optional
}GET /api/jobs?queue=email&status=pending&page=1&limit=20GET /api/jobs/:idDELETE /api/jobs/:idPOST /api/jobs/:id/retryGET /api/jobs/metricsPOST /api/jobs/queue/:queueName/drain| Job Name | Priority | Description |
|---|---|---|
send-welcome-email |
high | New user welcome |
send-password-reset |
high | Password reset link |
send-transactional |
medium | Order confirmations etc |
send-newsletter |
low | Bulk newsletter |
| Job Name | Priority | Description |
|---|---|---|
generate-analytics |
high | Analytics reports |
generate-pdf-report |
medium | PDF generation |
generate-csv-export |
low | Data exports |
generate-daily-digest |
low | Daily summaries |
| Job Name | Priority | Description |
|---|---|---|
send-push-notification |
high | Mobile push |
send-sms |
high | SMS messages |
send-slack-message |
medium | Slack alerts |
send-webhook |
medium | Webhook delivery |
Failed jobs retry automatically with exponential backoff:
Attempt 1 fails → wait 5s → retry
Attempt 2 fails → wait 10s → retry
Attempt 3 fails → wait 20s → dead letter queue
Configure via .env:
MAX_RETRIES=3
RETRY_DELAY_MS=5000
# All tests
npm test
# With coverage
npm run test:coverage
# Watch mode
npm run test:watch| Worker | Concurrency | Rationale |
|---|---|---|
| 10 | I/O-bound, fast | |
| Report | 3 | CPU-heavy |
| Notification | 15 | Very fast I/O |
Adjust via JOB_CONCURRENCY in .env or per-worker in the worker files.