Skip to content
Velloreth
Technology 5 min read

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

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

ConcernCronQueue
Triggera schedulean event
Retrynoyes
Backoffnoyes
Concurrencyuncontrolledlimited
Durabilitynoyes
Dead letternoyes
Visibilitya loga dashboard
Best fora recurring taskan 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.

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.

Frequently asked questions

What is the difference between cron and a job queue?
Cron runs a command at a scheduled time, and a job queue runs a job when it is enqueued. Cron is for a recurring task such as a nightly report, and a queue is for a task triggered by an event such as a new order. A queue adds a retry, a backoff, a concurrency limit and a dead-letter queue.
Can cron retry a failed job?
Not by itself. Cron runs the command and does not know whether it succeeded. A retry requires the command to handle it, or the job to be enqueued in a queue that has a retry policy. This is the main reason to combine cron with a queue.
What happens if two cron jobs overlap?
Both run, which can produce a duplicate or a race. A long job that runs every minute overlaps with itself. The fixes are a lock so only one instance runs, a longer interval, or a queue with a concurrency limit of one.
What is the pattern for a scheduled job that needs a retry?
A cron job enqueues a queue job. The cron provides the schedule and the queue provides the retry, the backoff, the concurrency limit and the dead-letter queue. The cron job itself does almost nothing, which makes it reliable.
Is cron reliable in a container?
A cron daemon in a container is fragile, because the container may be restarted and the schedule is lost. A platform scheduler such as a Kubernetes CronJob, a cloud scheduler or a workflow engine is more reliable, because the schedule is stored outside the container.
How do I run a job exactly once?
Use a lock with a timeout, or a unique constraint in the database. A distributed lock such as a Redis key with a TTL is the common approach. Exactly-once delivery is not achievable in general, so the job should be idempotent and the lock should prevent the common case of an overlap.