Retry & Backoff
When jobs fail, Monque automatically retries them using exponential backoff. This prevents overwhelming external services while ensuring jobs eventually complete.
Quick Reference
Section titled “Quick Reference”| Option / Property | Default | Description |
|---|---|---|
maxRetries | 10 | Maximum retry attempts |
baseRetryInterval | 1000ms | Base delay for backoff calculation |
maxBackoffDelay | 86400000ms | Maximum backoff cap (24h) |
Job.failCount | - | Number of failed attempts |
Job.failReason | - | Last error message |
How Retries Work
Section titled “How Retries Work”- Worker handler throws an error or returns rejected promise
failCountis incrementedfailReasonis set to the error message- If
failCount < maxRetries: schedule retry with backoff - If
failCount >= maxRetries: mark as permanentlyfailed
Backoff Formula
Section titled “Backoff Formula”Example Timeline
Section titled “Example Timeline”With default settings (baseRetryInterval: 1000ms, maxRetries: 10):
| Attempt | failCount | Delay | Total Wait |
|---|---|---|---|
| 1st retry | 1 | 2s | 2s |
| 2nd retry | 2 | 4s | 6s |
| 3rd retry | 3 | 8s | 14s |
| 4th retry | 4 | 16s | 30s |
| 5th retry | 5 | 32s | ~1 min |
| 6th retry | 6 | 64s | ~2 min |
| 7th retry | 7 | 128s | ~4 min |
| 8th retry | 8 | 256s | ~8.5 min |
| 9th retry | 9 | 512s | ~17 min |
| 10th retry | 10 | - | Failed permanently |
Configuration
Section titled “Configuration”Global Settings
Section titled “Global Settings”Configure retry behavior in MonqueOptions:
Configuration Options
Section titled “Configuration Options”| Option | Default | Description |
|---|---|---|
maxRetries | 10 | Maximum retry attempts before permanent failure |
baseRetryInterval | 1000 (1s) | Base delay multiplied by backoff factor |
maxBackoffDelay | 86400000 | Maximum delay cap (24 hours) |
Monitoring Retries
Section titled “Monitoring Retries”Via Events
Section titled “Via Events”Subscribe to job:fail events:
Via Job Properties
Section titled “Via Job Properties”Error Handling Patterns
Section titled “Error Handling Patterns”Transient vs Permanent Failures
Section titled “Transient vs Permanent Failures”Circuit Breaker Pattern
Section titled “Circuit Breaker Pattern”Recurring Job Retries
Section titled “Recurring Job Retries”For recurring jobs (schedule()), retry behavior differs:
- Failed job retries with exponential backoff
- After successful completion (including successful retry), job reschedules using original cron
- The retry delay is added to normal schedule
Example
Section titled “Example”Best Practices
Section titled “Best Practices”1. Set Appropriate Retry Limits
Section titled “1. Set Appropriate Retry Limits”2. Log Retry Context
Section titled “2. Log Retry Context”3. Handle Dead Letter Queue
Section titled “3. Handle Dead Letter Queue”4. Implement Backoff Jitter (Manual)
Section titled “4. Implement Backoff Jitter (Manual)”For high-volume systems, add jitter to prevent thundering herd:
Disabling Retries
Section titled “Disabling Retries”Set maxRetries: 0 for jobs that should never retry:
Next Steps
Section titled “Next Steps”- Jobs - Understand job lifecycle
- Workers - Configure worker behavior
- Change Streams - Real-time monitoring
API Reference
Section titled “API Reference”MonqueOptions- Retry configuration optionsJob- Job interface withfailCount,failReasonMonqueEventMap- Events includingjob:failMonqueError- Base error class