This guide provides crucial considerations and tips to help you achieve a robust solution when deploying your BullMQ-based application to production.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/taskforcesh/bullmq/llms.txt
Use this file to discover all available pages before exploring further.
Redis Configuration
Persistence
Since BullMQ is based on Redis, persistence needs to be configured manually. Many hosting solutions do not offer persistence by default.Enable AOF (Append Only File)
We recommend enabling AOF persistence, which provides a robust and fast solution.
Usually, 1 second per write is enough for most applications.
Max Memory Policy
Connection Management
Automatic Reconnections
In production, automatic recovery after connection issues is crucial for system robustness.BullMQ uses IORedis for Redis connections. Understanding these options is important:
retryStrategymaxRetriesPerRequestenableOfflineQueue
Different Behavior for Queue vs Worker
- Queue operations: Should fail quickly during temporal disconnections
- Worker operations: Should wait indefinitely without raising exceptions
retryStrategy
Determines how connection retries are performed. BullMQ uses this default strategy:- Exponential backoff
- Minimum 1-second retry time
- Maximum 20-second retry time
maxRetriesPerRequest
enableOfflineQueue
- For Queue instances: Disable the offline queue to fail quickly
- For Worker instances: Leave enabled to wait until connection is re-established
Error Handling
Log Errors
Attach error handlers to prevent unhandled errors and aid debugging:Unhandled Exceptions and Rejections
Handle unhandled exceptions gracefully at the application level:Graceful Shutdown
Why It Matters
Workers may be processing jobs when servers restart. Proper shutdown minimizes the risk of stalled jobs.If a worker is killed without waiting for jobs to complete, those jobs will be marked as stalled and automatically reprocessed after about 30 seconds when new workers come online.
Listen for Shutdown Signals
Listen for SIGINT and SIGTERM
SIGINT: Sent when user types Ctrl+CSIGTERM: Sent by system daemons, Kubernetes, PM2, etc.
Job Management
Auto-job Removal
By default, all jobs are kept forever. Configure automatic removal:You can also configure removal per job:
Protecting Sensitive Data
Production Checklist
Redis Configuration
Redis Configuration
- AOF persistence enabled
-
maxmemory-policyset tonoeviction - Proper memory allocation configured
- Redis version 6.2.0 or newer
Connection Management
Connection Management
- Retry strategy configured
-
maxRetriesPerRequestset tonullfor workers - Error handlers attached to queues and workers
- Offline queue settings appropriate for use case
Shutdown Handling
Shutdown Handling
- SIGINT handler implemented
- SIGTERM handler implemented
- Graceful shutdown tested
- Timeout handling for long-running jobs
Job Management
Job Management
- Auto-removal configured
- Sensitive data encrypted or excluded
- Job retry logic configured
- Monitoring and alerting set up
Error Handling
Error Handling
- Unhandled exception handler
- Unhandled rejection handler
- Error logging configured
- Error tracking service integrated
Related Resources
Troubleshooting
Common issues and solutions
Redis Hosting
Managed Redis hosting options
