Lesson 7 of 9 · 24m
Cron, systemd Timers, and Scheduling Across Timezones
Configure operational schedules intentionally: host timezone behavior, UTC discipline, systemd calendar syntax, overlap policy, and missed-run recovery.
Cron is simple until production makes it honest. The daemon uses system local time unless configured otherwise. Containers often run UTC while hosts do not. Daylight-saving transitions can skip or repeat wall-clock times. Deployments miss runs. Distributed workers overlap. A senior engineer treats scheduling as an execution policy, not a crontab string copied from a blog post.
Know which clock cron uses
Classic cron expressions describe local time on the machine running the daemon:
# minute hour day-of-month month day-of-week command
30 2 * * * /opt/app/bin/nightly-rollupIf the host timezone is America/New_York, 02:30 is a local schedule and can vanish during spring forward. If the host is UTC, it always exists but no longer means the same local operations window. Neither is inherently wrong. The wrong part is not knowing which one you deployed; write the intent beside the schedule, especially when UTC is deliberate.
Check the truth with timedatectl, systemctl cat cron.service, and crontab -l before assuming anything.
systemd timers are clearer about missed runs
A systemd timer can persist missed executions and express calendar events more readably:
[Timer]
OnCalendar=Mon..Fri 03:15:00 UTC
Persistent=true
[Install]
WantedBy=timers.targetPersistent=true runs a missed job after boot or downtime. That is desirable for billing and compaction; dangerous for jobs whose effect is harmful when late. For example, do not blindly send a "starting in 10 minutes" reminder ten hours after the event.
Overlap and idempotency are part of the schedule
A job that fires exactly once can still overlap if the previous run is slow. Use locking and idempotency keys:
flock -n /var/lock/nightly-rollup.lock /opt/app/bin/nightly-rollup --partition 2026-11-29Partition by logical date or tenant rather than "now" inside the worker. Then retries, backfills, and late runs process the same unit deterministically. A cron entry that says date -d yesterday without a timezone policy is a portability bug waiting for a host migration.
Kubernetes CronJobs add another layer
Kubernetes schedules are interpreted in the controller's timezone unless timeZone is set on supported versions:
spec:
schedule: "30 2 * * *"
timeZone: "America/New_York"
concurrencyPolicy: ForbidconcurrencyPolicy is not optional operational trivia. Forbid, Replace, and Allow produce very different behavior during slow runs and DST repeats.
Field notes
- Cron implementations differ: some support
CRON_TZ, some do not, and containers may not include the timezone database you expect. - Missed-run recovery must distinguish state-changing jobs from point-in-time notifications.
- Use monotonic deadlines inside workers even when the outer trigger is calendar-based.
- Record the intended partition or occurrence key in logs;
started_atalone cannot explain why a job ran.
Was this lesson helpful?