Cron vs Job Queues: When to Use Which
Cron runs on a schedule and a queue runs on an event. Learn the difference, the overlap, and the pattern that combines them.
By Velloreth
The two mechanisms
Cron runs a command at a scheduled time.
0 6 * * * /usr/bin/report.sh
A job queue runs a job when it is enqueued.
await queue.add('send-email', { to, subject });
The trigger is the difference. Cron is time-based and a queue is event-based.
What cron gives you
A schedule. Every minute, every hour, every day at 6am.
Simplicity. A line in a crontab, or a scheduled workflow.
What it does not give you:
- A retry
- A backoff
- A concurrency limit
- A dead-letter queue
- A durable record of the run
- A way to know whether the command succeeded
Cron runs the command and moves on. A failure is a line in a log that nobody reads.
What a queue gives you
A retry with a backoff. A transient failure is retried.
A concurrency limit. The number of workers is controlled.
A dead-letter queue. A job that fails every attempt is preserved.
A durable record. The job is stored, and its state is visible.
A delay and a repeat. A job can be scheduled, which overlaps with cron.
What it does not give you: a wall-clock schedule. A queue job runs when it is enqueued, not at 6am.
The comparison
| Concern | Cron | Queue |
|---|---|---|
| Trigger | a schedule | an event |
| Retry | no | yes |
| Backoff | no | yes |
| Concurrency | uncontrolled | limited |
| Durability | no | yes |
| Dead letter | no | yes |
| Visibility | a log | a dashboard |
| Best for | a recurring task | an event-driven task |
The overlap
A queue can schedule a job.
await queue.add('report', data, { repeat: { cron: '0 6 * * *' } });
This is a queue with a cron feature. It is the best of both: the schedule and the retry.
The caution: the schedule is stored in the queue, so a queue that is reset loses it. A platform scheduler is more durable.
The pattern
A cron job that enqueues a queue job.
// The cron job: enqueue one job per user
const users = await db.users.findAll();
for (const user of users) {
await queue.add('send-digest', { userId: user.id });
}
The cron provides the schedule, and the queue provides the retry, the backoff, the concurrency limit and the dead-letter queue.
The cron job does almost nothing, which makes it reliable. A failure in the enqueue is the only failure mode, and it is a fast operation.
The worker does the work, and a failure is retried.
Overlap
A long job that runs every minute overlaps with itself.
The consequences: a duplicate, a race, or a resource exhaustion.
The fixes:
A lock. Only one instance runs.
const lock = await redis.set('lock:report', '1', 'EX', 300, 'NX');
if (!lock) return; // another instance is running
A longer interval. If the job takes five minutes, do not run it every minute.
A queue with a concurrency of one. The jobs queue up rather than overlap.
A flock for a shell script.
flock -n /tmp/report.lock /usr/bin/report.sh
Reliability
A cron job on one server is a single point of failure. The server is down and the job does not run.
The fixes:
A platform scheduler. A Kubernetes CronJob, a cloud scheduler, or a workflow engine. The schedule is stored outside the process.
A distributed lock. Several servers run the cron, and the lock ensures one executes.
A missed-run policy. A scheduler that catches up a missed run, or one that skips it. The choice matters: a nightly report that is missed should run late, and a heartbeat that is missed should be skipped.
A monitoring check. A job that did not run is a failure that is invisible without a check. Alert on the absence of a success, not only on an error.
Choosing
A recurring task with no retry need: cron.
A task triggered by an event: a queue.
A recurring task that must be retried: a cron job that enqueues a queue job.
A task that must run exactly once: a queue with a lock, or a unique constraint.
A task that must run at a wall-clock time: a scheduler, not a queue.
Choosing in a real system
A real system usually has both, and the choice is per task rather than per system. A nightly report is a cron job, a password reset email is a queue job, and a nightly report that must be retried is a cron job that enqueues a queue job. The second consideration is the failure mode: a cron job that fails is silent, so it needs a monitoring check on the absence of a success, and a queue job that fails is retried and then dead-lettered, so it needs a dashboard. The third is the volume: a cron job that enqueues a million jobs at once floods the queue, so it should enqueue in batches or spread the work. The fourth is the timezone: a cron expression is evaluated in a timezone, and a job that must run at a local time needs the timezone set explicitly, because a server in UTC runs it at a different hour.
Common mistakes
A cron job that does the work directly. No retry, no visibility.
No lock. Two instances overlap.
A cron job in a container. The schedule is lost on a restart.
No monitoring of the absence. A job that did not run is invisible.
A queue job that assumes a wall-clock time. It runs when it is enqueued.
A repeatable job in a queue that is reset. The schedule is lost.
A cron expression that is wrong. A five-field expression is easy to misread. Test it.
A job that is not idempotent. A retry or an overlap runs it twice.
A quotable summary
Cron triggers on a schedule and a queue triggers on an event, and cron has no retry, no concurrency control and no durability. A queue adds a retry, a backoff, a concurrency limit and a dead-letter queue, and it can also schedule a job. The common pattern is a cron job that enqueues a queue job, so the cron provides the schedule and the queue provides the reliability, and a lock prevents an overlap.
Related reading
For the queue side, see background-jobs-guide and cron-expressions-explained. For the broader context, rest-api-rate-limiting and api-error-responses-guide.