Definition: Cron is a time-based job scheduler that automatically runs commands or tasks at specified times or recurring intervals, without a person having to trigger them manually. (man7.org)
In a backend, you can use it for background jobs such as cleanup, backups, report generation, or periodically checking something. (Linuxize)
Simple example
Suppose you want to delete expired sessions every night:
Cron Scheduler
│
Every night
at 02:00
↓
cleanupExpiredSessions()You don’t need a user to click anything. Cron automatically starts the task at 02:00.
3 examples
1. Database backup
Every day at 03:00
↓
Backup PostgreSQL database2. Cleanup
Every hour
↓
Delete expired sessions
↓
Delete temporary files3. Generate reports
Every Monday at 08:00
↓
Generate weekly sales report
↓
Send it to the managerWhat does a cron expression mean?
A standard Unix cron schedule has five time fields:
* * * * *
│ │ │ │ │
│ │ │ │ └── Day of week
│ │ │ └──── Month
│ │ └────── Day of month
│ └──────── Hour
└────────── MinuteFor example:
0 2 * * *means:
Run at 02:00 every day. (man7.org)
Cron vs. normal code
The important distinction is:
Normal function:
User/API request
↓
Function()Cron job:
Clock
↓
Scheduled time
↓
Function()So when someone says:
“Use a background job scheduler / cron.”
they basically mean:
“Run this task automatically in the background at a particular time or interval, rather than waiting for a user request.”
One small distinction: classic Unix cron is primarily for recurring schedules. If you need something like “run this once 20 minutes from now,” a job queue/scheduler or a one-time scheduler may be more appropriate. (Debian)