logo
Parslinks
Back to blog
Guides4 min read

Scheduled jobs in production: cron that never runs twice and never fails silently

Cron looks trivial until your app has two instances, or the nightly report quietly stops for three nights.

Alireza Tadi

Co-founder & Head of Development and Communications, Parslinks

A language-learning app sends a "time for today's lesson" push every evening at 7 p.m. local time. After the team scaled the web tier to three instances for a marketing launch, users started getting three identical notifications. The scheduler was running inside the web process, so it now ran three times.

A month later the opposite happened. The weekly streak-report job failed on a database timeout three weeks in a row, and nobody noticed until a user asked why their summary email had stopped.

Mistake one: cron inside every instance

Libraries like node-cron, or a framework's built-in scheduler, run inside your app process. With one instance, fine. With two or more, each runs the job independently.

Three common fixes:

  • A dedicated scheduler process: one process, one instance, that only runs scheduled jobs. The simplest and most predictable option.
  • Platform cron: most platforms let you define a scheduled command that runs once at a set time.
  • A shared lock: if the scheduler must stay in the app, take a lock in Redis or the database before each run so only one instance does the work.
Common cron mistakes

Mistake two: jobs that can't run twice

Even with a single scheduler, a job can run twice: the server restarts mid-run and the job starts over, or a slow run overlaps with the next tick.

Make reruns harmless. For reminder pushes, record "sent for user X on date Y" before sending, and skip if it's already there. It's the same pattern as idempotent payment callbacks, applied to scheduled work.

Mistake three: silent failure

Failed cron jobs make no noise. You need two kinds of monitoring:

  1. Errors: when a job throws, send an alert.
  2. Missed runs: more important. If the scheduler itself has stopped, nothing errors. Ping a heartbeat at the end of every successful run, and alert when the expected ping doesn't arrive.

Put this next to your four core monitoring signals.

crontab
# every evening at 19:00 in the users' main time zone
CRON_TZ=Europe/Berlin
0 19 * * *  node dist/jobs/send-reminders.js && curl -fsS https://heartbeat.example.com/reminders
bash3 lines

Long-running jobs

If a job takes more than a few minutes, like building a yearly report or emailing 100,000 people, the scheduler should only enqueue it and let a queue worker do the work. A long job then doesn't block the next ones, and if it fails halfway, the queue retries it.

The language app now has a dedicated scheduler process, records each reminder before sending and pings a heartbeat after every job. Users get one notification, and a missed weekly report pages someone the same morning.

Frequently asked questions

Alireza Tadi

About the author

Alireza Tadi

Co-founder & Head of Development and Communications, Parslinks

Writes about how software products grow, what the market needs, and the challenges Iranian teams face in choosing and using deployment platforms.

Join the discussion

No comments yet. Be the first to share your thoughts.