Scheduling and dead letters
Local baseline: Node.js 22.16.0, ECMAScript modules, synthetic data. Run each complete example independently as node main.mjs in a disposable directory. Static ByteMind blocks do not imply live Node execution. SQLite is experimental in this baseline. Third-party integrations below are staged candidates, not installed or validated dependencies.
Decide whether a failed attempt can retry
function retry({attempt,transient}) { if(!transient||attempt>=3)return null; return 250*2**(attempt-1);}for(const state of [{attempt:1,transient:true},{attempt:2,transient:true},{attempt:3,transient:true},{attempt:1,transient:false}])console.log(retry(state));Expected output:
250500nullnullThree total attempts allow only two retries. Permanent failures stop immediately.
How it works
Classify failures before retrying: malformed input is usually permanent, while a temporary unavailable dependency may recover. Bound total attempts and elapsed time; apply backoff and jitter to reduce synchronized retries. BullMQ attempts counts the initial run as well as retries. Its failed set is not automatically a separate dead-letter queue; design retention and explicit redrive rules. Scheduling recurring jobs also needs overlap and missed-run policies. Store a stable run ID, a time zone when using calendar schedules, and a lease or equivalent ownership strategy when multiple schedulers can run. Monitor age, queue depth, retries and final failures.
Select due jobs using a fixed clock
const jobs=[{id:'a',due:100},{id:'b',due:105},{id:'c',due:100}];const now=100;const dispatched=new Set(['a']);const ready=jobs.filter(j=>j.due<=now&&!dispatched.has(j.id));console.log(ready.map(j=>j.id).join(','));console.log(jobs.filter(j=>j.due>now).map(j=>j.id).join(','));Expected output:
cbAlready dispatched run a is excluded; c is due and b is not. A real scheduler requires durable coordination.
Common mistakes
Do not retry every failure forever. Do not redrive a failed job without considering its previous effects. A scheduled time is not a guarantee of exact execution time.
Practice and next steps
For a three-attempt policy with base delay 250 ms, list the maximum number of retries and the delays before them. Define what happens when the same scheduled run is offered twice.
Further reading: https://docs.bullmq.io/guide/retrying-failing-jobs. Related staged reference: node-scheduling-and-dead-letters-lookup (route not verified).
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Scheduling and dead letters — knowledge check
Apply the lesson to a fresh scenario and identify the failure boundary.
Three total attempts permits how many retries after the first failure?
Which failure should normally stop without retries?
What is required before redriving a failed job?