Cron jobs and schedulers with BullMQ in Node.js

Learn to schedule recurring tasks with BullMQ and Redis in Node.js. Includes cron, schedulers, NestJS, and best practices for production.

domingo, 5 de julio de 2026 • 3 min read • Q2BSTUDIO Team

Schedulers and cron with BullMQ: a robust alternative

In modern application development with Node.js, executing scheduled tasks is a common requirement that can be addressed in multiple ways. While solutions like node-cron or @nestjs/schedule work correctly in single-instance environments, they present limitations when resilience against restarts, deduplication across replicas, or integration with other asynchronous processes is needed. This is where BullMQ positions itself as a solid alternative, relying on Redis to manage queues and schedulers in a centralized manner.

BullMQ offers the so-called Job Schedulers, which allow enqueuing recurring jobs following cron patterns or fixed intervals. Unlike in-process timers, these schedulers persist in Redis, survive server crashes, and are shared by multiple workers. Additionally, they inherit the retry, backoff, and concurrency capabilities that BullMQ provides for one-off jobs. This makes schedulers a key piece for scalable architectures, where the same worker is required to process both periodic tasks and on-demand jobs.

Implementation in Node.js is straightforward: a queue and a worker are created sharing a Redis connection, and the scheduler is registered using the upsertJobScheduler method. For example, a pattern like */10 * * * * * generates a heartbeat every ten seconds, while a cron with a specific timezone allows executing daily cleanups at 03:15 local time. It is essential to remember that the worker must be active to consume the jobs; otherwise, they will accumulate in Redis. It is also important to avoid the deprecated repeat option in favor of the schedulers API introduced in BullMQ 5.16+.

In the NestJS ecosystem, integration is simplified thanks to the @nestjs/bullmq module. A global Redis connection is configured, the queue is registered as a provider, and it is injected into a service that implements OnModuleInit to upsert the schedulers when the application starts. Workers are defined as classes decorated with @Processor, inheriting from WorkerHost. This pattern ensures that each deployment updates existing schedulers without duplicating them, maintaining stable identity through a unique identifier.

Among the best operational practices are: properly closing the worker and queue on SIGINT/SIGTERM signals, using getJobSchedulers to inspect active schedulers, and employing removeJobScheduler to remove obsolete schedules. It is crucial not to mix pattern and every in the same scheduler, and to specify the timezone when local time is relevant. Likewise, under high loads, intervals may lengthen because BullMQ schedules the next job only when the previous one begins processing.

In enterprise environments, combining BullMQ with cloud services like AWS or Azure enhances scalability and resilience. For example, hosting Redis on ElastiCache or Azure Cache for Redis, and deploying workers in orchestrated containers, allows handling load spikes without losing scheduled jobs. At Q2BSTUDIO, we develop custom applications that integrate these patterns, offering robust solutions for process automation and critical task management. Additionally, our capabilities include process automation with message queues, artificial intelligence for businesses, AI agents, cybersecurity, and business intelligence services with Power BI, all on AWS and Azure cloud infrastructures.

In summary, BullMQ Job Schedulers represent a natural evolution over in-process timers when reliability, concurrency, and observability are required. Their use is especially recommended in multi-instance architectures and in combination with other queue systems. From Q2BSTUDIO, we accompany organizations in implementing these technologies, as well as in developing custom software that integrates schedulers, cloud, AI, and business intelligence to drive digital transformation.

A BREAK?

Play for a moment before you go

OUR SERVICES

How we can help you

Do you have a project in mind?

Tell us your vision and we'll turn it into a software solution. Whatever the scope, we make your idea real.