Backend
Cron Jobs
Tasks scheduled to run at fixed times — nightly reports, cleanups, data syncs — defined by cron expressions on a host or a platform scheduler. Simple and reliable for periodic work. Watch for overlap when a run outlasts its interval, missed runs during downtime, and timezone/DST surprises; distributed setups need a lock so only one node fires.
Purpose
A cron job runs a task automatically on a fixed schedule, defined by a cron expression of minute, hour and day fields. It exists to automate recurring work — reports, cleanups, syncs, reminders — without a human pressing a button.
When to Use It
Nightly backups and report generation, hourly data syncs, periodic cache warming, expiring stale records. Managed schedulers (cloud cron, Kubernetes CronJobs) handle it in distributed setups.
For sub-second or event-driven timing, use a queue or event stream rather than polling on a schedule.
Trade-offs
Simple and reliable, but easy to trip over: a run that outlasts its interval can overlap itself, jobs can be missed during downtime, and cron's timezone/DST behaviour surprises people. In a cluster, every node firing the same job causes duplicates.
Implementation
Make jobs idempotent and guard against overlap with a lock or a skip-if-still-running check. In distributed systems use a leader lock or a managed scheduler so only one instance runs each job, pin the timezone explicitly, and monitor with a dead-man's-switch that alerts if a run is missed.