Create background job processing
✓Works with OpenClaudeYou are a backend engineer implementing asynchronous background job processing. The user wants to create a reliable system for queuing, processing, and tracking jobs that run outside the request/response cycle.
What to check first
- Verify you have a message queue (Redis, RabbitMQ) or job queue library installed:
npm list bullornpm list bullmq - Check your Node.js version supports Worker Threads:
node --version(v10.5.0+) - Confirm database connectivity for job persistence and status tracking
Steps
- Install Bull or BullMQ:
npm install bullmq redis(Bull is simpler for small projects, BullMQ is more robust) - Set up a Redis connection in your config file with host, port, and optional password
- Create a queue instance by calling
new Queue('jobName', { connection: redis })with your Redis config - Define job producers that add jobs to the queue using
queue.add('jobType', data, { options }) - Create job consumers (workers) that process jobs with
.process()or by instantiating aWorkerclass - Implement error handling with retry logic using
{ attempts: 3, backoff: { type: 'exponential' } } - Add event listeners for job completion (
queue.on('completed')) and failures (queue.on('failed')) - Track job status in your database or use Bull's built-in job tracking with
job.progress()for long-running tasks
Code
const Queue = require('bullmq').Queue;
const Worker = require('bullmq').Worker;
const Redis = require('redis');
// Initialize Redis connection
const redisConnection = {
host: process.env.REDIS_HOST || 'localhost',
port: process.env.REDIS_PORT || 6379,
};
// Create queue instance
const emailQueue = new Queue('emails', { connection: redisConnection });
// Producer: Add job to queue
async function sendEmailJob(userEmail, subject, body) {
const job = await emailQueue.add(
'send-email',
{ email: userEmail, subject, body },
{
attempts: 3,
backoff: { type: 'exponential', delay: 2000 },
removeOnComplete: true,
removeOnFailed: false,
}
);
return job.id;
}
// Consumer: Process jobs with Worker
const worker = new Worker('emails', async (job) => {
console.log(`Processing job ${job.id}: ${job.data.email}`);
try {
// Simulate email sending
await new Promise((resolve) => setTimeout(resolve, 2000));
if (job.data.email === 'invalid@test.com') {
throw new Error('Invalid email address');
}
job.progress(100);
return { status: 'sent',
Note: this example was truncated in the source. See the GitHub repo for the latest full version.
Common Pitfalls
- Treating this skill as a one-shot solution — most workflows need iteration and verification
- Skipping the verification steps — you don't know it worked until you measure
- Applying this skill without understanding the underlying problem — read the related docs first
When NOT to Use This Skill
- When a simpler manual approach would take less than 10 minutes
- On critical production systems without testing in staging first
- When you don't have permission or authorization to make these changes
How to Verify It Worked
- Run the verification steps documented above
- Compare the output against your expected baseline
- Check logs for any warnings or errors — silent failures are the worst kind
Production Considerations
- Test in staging before deploying to production
- Have a rollback plan — every change should be reversible
- Monitor the affected systems for at least 24 hours after the change
Related Backend Skills
Other Claude Code skills in the same category — free to download.
Express Setup
Scaffold Express.js app with best practices
Fastify Setup
Scaffold Fastify app with plugins
NestJS Module
Generate NestJS modules, controllers, services
Middleware Chain
Create and organize middleware chain
Queue Worker
Set up job queue with Bull/BullMQ
File Upload Handler
Create file upload handling with validation
Email Service
Set up transactional email service
WebSocket Setup
Implement WebSocket server with rooms
Want a Backend skill personalized to YOUR project?
This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.