Untitled Lesson
Skill Matrix
UNLOCK NODES BY LEARNING NEW TAGS.
Why does using setInterval directly for a recurring task cause a problem specifically in a horizontally-scaled, multi-instance deployment?
💻 Code Challenge | +75 XP
Set up a BullMQ repeatable job configured to run daily at 9am UTC, and explain in a comment why this is safe to configure identically across multiple worker replicas.
A daily digest email is being sent to every user 5 times instead of once, correlating with the application running 5 replicas in production. Reorder the steps to diagnose and fix the root cause.
Task: Reorder the blocks in logical sequence to solve the problem.
A.D.A. Interface
Adaptive Didactic Assistant

Pascual Vila
Frontend Instructor // Code Syllabus
The Error //
Using setInterval directly for a recurring task in an application deployed with multiple replicas
// Wrong: runs once PER REPLICA, not once total
setInterval(sendDailyDigest, 24 * 60 * 60 * 1000);
// Correct: Redis-coordinated, exactly one execution regardless of replica count
await queue.add("dailyDigest", {}, { repeat: { pattern: "0 9 * * *" } });The Solution //
Each replica runs its own completely independent setInterval timer with no awareness of the others, meaning a task intended to run once actually executes once per replica simultaneously — a silent multiplication bug that can cause duplicate emails, duplicate charges, or other duplicated side effects. Use a distributed-safe scheduling mechanism instead, like BullMQ repeatable jobs or a Kubernetes CronJob.
The Error //
Scheduling a cron job without explicitly specifying its intended timezone
// Ambiguous: depends on the server's ambient local timezone
new CronJob("0 9 * * *", task);
// Correct: explicit, unambiguous
new CronJob("0 9 * * *", task, null, true, "America/New_York");The Solution //
A cron schedule with no explicit timezone typically runs based on the server's local timezone (which may not be UTC, and may even differ between deployment environments) — this can cause a job intended to run at 9am in a specific business timezone to actually run at an unintended hour. Always specify the timezone explicitly.