Production Checklist
Before deploying Monque to production, review this checklist to avoid common pitfalls and ensure reliable job processing.
Quick Reference
Section titled “Quick Reference”| Topic | Key Point |
|---|---|
| Idempotency | Workers must handle duplicate execution safely |
| Deduplication | Use uniqueKey to prevent duplicate jobs |
| Replica Set | Required for Change Streams |
| Shutdown | Configure shutdownTimeout appropriately |
| Lock Timeout | Set lockTimeout to 2× longest job duration |
1. Design for Idempotency
Section titled “1. Design for Idempotency”Jobs may be executed more than once due to:
- Retries: Failed jobs are automatically retried with exponential backoff
- Stale Recovery: If a worker crashes, the heartbeat mechanism recovers stuck jobs
- Network Issues: Transient failures during completion acknowledgment
Idempotency Patterns
Section titled “Idempotency Patterns”See Idempotent Operations for more patterns.
2. Use uniqueKey for Deduplication
Section titled “2. Use uniqueKey for Deduplication”Prevent duplicate jobs from being enqueued using uniqueKey:
Always Use uniqueKey for Scheduled Jobs
Section titled “Always Use uniqueKey for Scheduled Jobs”Without uniqueKey, calling schedule() multiple times (e.g., on each app restart) creates duplicate scheduled jobs.
3. MongoDB Replica Set Required
Section titled “3. MongoDB Replica Set Required”Without a replica set:
- Monque falls back to polling only
- Job pickup latency increases to
pollInterval(default: 1000ms) - Real-time job notifications are unavailable
Local Development with Replica Set
Section titled “Local Development with Replica Set”Use Docker Compose for local development:
Initialize the replica set:
4. Configure Graceful Shutdown
Section titled “4. Configure Graceful Shutdown”Ensure in-progress jobs complete before your application exits:
Kubernetes Considerations
Section titled “Kubernetes Considerations”Set terminationGracePeriodSeconds higher than shutdownTimeout:
5. Tune lockTimeout for Your Workload
Section titled “5. Tune lockTimeout for Your Workload”The lockTimeout determines how long a job can remain in processing before it’s considered stale and recovered.
Symptoms of Incorrect lockTimeout
Section titled “Symptoms of Incorrect lockTimeout”| Symptom | Likely Cause |
|---|---|
| Jobs running twice | lockTimeout too short |
Jobs stuck in processing | Worker crashed, recoverStaleJobs: false |
| Slow failure detection | lockTimeout too long |
6. Set Appropriate Concurrency
Section titled “6. Set Appropriate Concurrency”Configure workerConcurrency and per-worker concurrency based on your workload:
Instance-level Throttling
Section titled “Instance-level Throttling”Use instanceConcurrency to limit the total jobs processed by a single instance across all workers:
This prevents a single instance from overwhelming system resources when running multiple high-concurrency workers.
See Concurrency Strategy for guidelines.
7. Consider Producer-Consumer Architecture
Section titled “7. Consider Producer-Consumer Architecture”For high-scale deployments, separate job producers (API servers) from consumers (worker servers):
Benefits
Section titled “Benefits”- Independent Scaling: Scale API and worker tiers separately based on load
- Resource Isolation: API response times unaffected by background job processing
- Deployment Flexibility: Deploy worker updates without touching API servers
Implementation
Section titled “Implementation”Ts.ED Integration:
Core Package:
See Ts.ED Producer-only Mode for details.
8. Monitor Job Events
Section titled “8. Monitor Job Events”Subscribe to events for observability:
See MonqueEventMap for all available events.
9. Configure Job Retention
Section titled “9. Configure Job Retention”Prevent unbounded database growth by configuring retention:
10. Ensure Index Permissions
Section titled “10. Ensure Index Permissions”Monque creates MongoDB indexes during initialize(). Your database user must have index creation permissions.
If index creation is restricted in production, create indexes ahead of time:
See Indexes for the complete list.
Pre-Deployment Checklist
Section titled “Pre-Deployment Checklist”- Workers are idempotent (safe for duplicate execution)
- Scheduled jobs use
uniqueKey - MongoDB is a replica set (for Change Streams)
-
SIGTERMhandler callsmonque.stop() -
lockTimeoutis 2× longest job duration - Concurrency matches workload characteristics
-
instanceConcurrencyconfigured if running multiple workers - Producer-consumer separation considered for high-scale deployments
- Event handlers for
job:failandstale:recovered - Job retention is configured
- Database user has index creation permissions (or indexes pre-created)
API Reference
Section titled “API Reference”Monque- Main scheduler classMonqueOptions- Configuration optionsMonqueEventMap- Available eventsEnqueueOptions- Job enqueue optionsWorkerOptions- Worker configuration