Cron jobs for web apps are simple to write but easy to misconfigure. This guide explains how to create and validate cron expressions, handle time zones and daylight-saving changes, configure scheduled tasks on hosted and serverless platforms, and monitor reliability so recurring work runs at the right time without creating duplicate or invisible failures.
Overview
A cron job is a scheduled task that runs a command or calls an endpoint at defined intervals. Common examples include sending digest emails, deleting expired sessions, refreshing cached data, generating reports, processing queued records, and checking integrations.
In a traditional server, a cron daemon runs the schedule. In cloud-native applications, scheduling may be provided by an app deployment platform, a serverless scheduler, a managed workflow service, or a separate hosted cron service that sends an authenticated HTTP request. The implementation differs, but the operational questions are the same:
- What should run, and how often?
- Which time zone controls the schedule?
- What happens if a run is delayed, repeated, or interrupted?
- How will the team know that a job failed?
- Can the task be run safely more than once?
Use a cron expression builder or validator when creating a schedule, but do not treat validation as a complete reliability check. A syntactically valid expression can still run at an unsuitable time, overlap with another execution, or trigger an endpoint without sufficient authentication.
What to track
Cron expression fields
Most Unix-style cron expressions use five fields, in this order:
| Field | Allowed values | Example |
|---|---|---|
| Minute | 0–59 | 15 |
| Hour | 0–23 | 2 |
| Day of month | 1–31 | 1 |
| Month | 1–12 | 1 for January |
| Day of week | Typically 0–6 or 1–7 | 1 may represent Monday |
Common operators include an asterisk for every allowed value, a comma for a list, a hyphen for a range, and a slash for an interval. For example:
*/10 * * * *runs every 10 minutes.0 2 * * *runs at 02:00 every day in the scheduler's configured time zone.0 9 * * 1-5runs at 09:00 on weekdays.30 1 1 * *runs at 01:30 on the first day of each month.
Confirm the scheduler's dialect before relying on advanced syntax. Some systems support a sixth field for seconds, named months or weekdays, special characters, or a time-zone declaration; others reject those features. Day-of-month and day-of-week behavior can also vary when both fields are restricted, so test the exact platform rather than assuming that every cron implementation behaves identically.
Schedule intent and time zone
Record the schedule in plain language beside the expression. “Every day at 02:00 UTC” is more useful during an incident than a bare expression. If the requirement is “at 9:00 a.m. for users in New York,” decide whether the job should follow a fixed UTC time or a regional civil time. Those are different requirements when daylight-saving time changes.
For a fixed UTC schedule, convert the desired local time for the relevant date and document that conversion. For a local-time schedule, use a scheduler that supports an explicit IANA time zone such as America/New_York, or design the application to calculate the next run using a time-zone-aware library. Avoid relying on the server's local time unless it is explicitly controlled and documented.
Execution and outcome data
Track at least the scheduled time, actual start time, completion time, status, duration, records processed, and error details. A run identifier helps connect scheduler logs, application logs, database changes, and alerts. Also track whether a run was skipped, timed out, retried, or overlapped with an earlier run.
For HTTP-based cloud cron jobs, log the request method, route, response status, and correlation ID. Protect the endpoint with a secret or signed request, and reject unauthenticated calls. Do not place credentials directly in a cron expression or URL that may appear in dashboard history or logs. For related authentication checks, see the API Authentication Testing Guide.
Cadence and checkpoints
Before the first deployment
- Write the intended schedule in plain language and select the time zone.
- Validate the expression with a trusted tool and inspect several upcoming run times.
- Confirm that the platform supports the expression format, minimum interval, timeout, and execution duration you need.
- Make the task idempotent: repeating the same request should not send duplicate messages, charge a customer twice, or corrupt state.
- Define a timeout and decide whether retries are safe.
- Test the task against a small, representative dataset.
Platform setup checkpoint
Hosted app deployment platforms and serverless environments commonly expose scheduled functions or cron jobs through a project dashboard or configuration file. The exact labels and limits change, so verify the current documentation for the platform you use. The setup pattern is usually:
- Deploy the function or protected API route.
- Set production environment variables for database connections, API credentials, and the cron authentication secret.
- Add the expression and, where available, an explicit time zone.
- Enable the schedule in the correct environment; avoid accidentally enabling production work in a preview environment.
- Run a manual test or wait for the first scheduled execution.
- Confirm logs, response status, database effects, and alert delivery.
Platforms such as Vercel, Netlify, Render, and Railway can differ in how they define scheduled work, invoke functions, expose logs, and handle long-running processes. Treat a provider's dashboard as an implementation detail, not as the job's reliability strategy. The cloud-native deployment checklist can help place scheduled work alongside environment, monitoring, and rollback checks.
Recurring review cadence
Review critical jobs at least monthly or quarterly, depending on their business impact. At each checkpoint, compare the expected and actual run counts, failure rate, duration, timeout events, retry volume, and records processed. Review the last successful run rather than assuming that an absence of an alert means success.
Include scheduled work in cloud cost reviews. A frequent job that scans an entire table, invokes a serverless function, or generates large logs can become an avoidable source of usage. The cloud app cost review template provides a broader way to examine hosting, database, and serverless consumption.
How to interpret changes
A missed run is not always a cron syntax problem. Separate the incident into scheduling, invocation, application, and downstream stages:
- Scheduling: Was the job enabled, and did the scheduler record an attempted run?
- Invocation: Did the request reach the function or endpoint, and was authentication accepted?
- Application: Did the code fail, exceed its timeout, or encounter a database or API error?
- Downstream work: Did the task complete its intended side effect, or did it stop partway through?
Longer execution times can indicate data growth, a query-plan change, an external service slowdown, or an accumulating backlog. A sudden drop in records processed may mean there was no work, but it may also indicate a filter, permission, or time-zone bug. Compare the run with application metrics and business records before changing the schedule.
Retries require special care. Use bounded retries with backoff for transient failures, but do not automatically retry validation errors or unauthorized requests. Add a lock, lease, or database-based claim when overlapping executions could process the same records. For large workloads, prefer a short scheduled dispatcher that places items on a queue over a single function that attempts all work in one invocation.
Daylight-saving changes deserve a specific test. A local-time job may run at an ambiguous time, run once at an unexpected UTC time, or have no matching clock time on the transition day. Decide whether that behavior is acceptable, document it, and test the relevant dates before they arrive.
When to revisit
Revisit a cron job whenever its data volume, business purpose, platform, or time-zone requirement changes. Also review it after a migration between app deployment platforms, a change to serverless limits, a database redesign, or an incident involving duplicate or missing work.
Use this practical checklist during the next review:
- Copy the expression into a validator and inspect the next several run times.
- Confirm the documented time zone matches the scheduler's actual setting.
- Check the last successful run, recent failures, duration, retries, and timeout events.
- Verify idempotency, locking, authentication, and secret rotation.
- Test a controlled failure and confirm that logs and alerts identify the affected job.
- Compare execution volume and cost with the job's current value.
- Update the runbook with the owner, purpose, schedule, dependencies, recovery steps, and platform configuration.
Keep a small schedule inventory for every production task. When you change an expression, record why, what time zone it uses, and how the change was tested. That habit turns cron from an opaque line of configuration into an observable part of your application workflow—and gives your team a reliable reference whenever a recurring task needs to be added, moved, or repaired.