DEV Community

delay.run
delay.run

Posted on

When the scheduler comes back after an outage, should it run every missed tick, or skip to the next one? Let's argue about it

Reliable HTTP cron and delayed-job scheduling with automatic retries and full run logs — delay.run

The scheduler is down for six hours. The job is "every five minutes". When the scheduler comes back, you have two honest options: run every missed tick (72 runs, as fast as the worker will take them), or skip the gap and wait for the next wall-clock slot. Most platforms pick one of these as a default and then surprise you with it during an incident.

systemd's Persistent=true, Kubernetes startingDeadlineSeconds, and a lot of cron wrappers each have a slightly different answer. The argument is not which tool is right. It is which missed ticks are still worth running.

Let's argue about it.

The case for catching up every missed tick

Some work is a tick, not a snapshot. "Every five minutes, pull new payments and book them" is a cursor over a stream. If you skip six hours, you skipped six hours of events, unless the job is written to notice the gap and catch up internally. A lot of jobs are not written that way. They process "what arrived since the last run", assume the last run was five minutes ago, and quietly drop everything in between.

You already promised a schedule. A report that is supposed to go out at 09:00, 12:00 and 17:00 should still go out, late, if the box was down at 09:00. "We skipped it because the scheduler was sad" is not a policy a finance team will accept.

Catch-up is recoverable if the job is idempotent and cheap. If each tick is "look at a watermark, process the next unprocessed row, advance the watermark", 72 runs in a row are just 72 loops. The queue gets a bump, and you are current. This is the best version of the argument, and it only holds if the job was designed for it.

Skipping hides how long you were wrong. A metric that says "the job ran at 16:02, on time" after a six-hour hole will look healthy. A burst of 72 runs, each stamped with the tick it belongs to, is an honest recovery.

The case for skipping to the next tick

A six-hour catch-up can be a second outage. "Every five minutes, rebuild the search index" or "call a rate-limited API" or "send the digest email" will, if you replay every tick, stampede your own database, trip a provider, or send 72 copies of the same email. The scheduler coming back should not be the loudest event of the day.

A lot of jobs already mean 'the latest state', not 'each slot'. "Refresh this cache", "sync the latest exchange rates", "check whether the certificate has expired": running once now is the whole value. The 71 missed ticks add nothing, and they delay the one run that does.

You may not have the capacity. Workers that were sized for "one run every five minutes" will not drain 72 overlapping runs if the job also has concurrencyPolicy: Allow (or no lock). Overlap was a known class of bug before the outage; catch-up makes it certain.

Catch-up without a watermark is a guess. If the job has no record of what it last processed, "run 72 times" does not reconstruct the missed windows. It just runs "now" 72 times. That is skip, with more damage.

Where I've landed

I want the policy to be per job, written down, and boring during the incident.

  1. Default to skip, with an explicit catch-up for jobs that have a watermark. "Latest state" jobs (caches, health snapshots, 'is the cert still valid') skip. "Cursor over a stream" jobs catch up, but they should do it inside one run ("process everything since the last successful watermark") rather than as 72 separate ticks that can overlap. If you need 72 ticks to do the work, the job is missing a cursor.
  2. Never catch up a send. Email, SMS, push, Slack, invoices that charge a card. If the 09:00 send was missed, decide — once, in a runbook — whether a human sends a late copy, or whether you wait for 12:00. A scheduler should not make that decision by replaying a backlog.
  3. Cap catch-up, even when you allow it. A maximum of N missed windows, or a maximum of T minutes, after which you skip and alert. An outage that lasted three days should not replay three days of "every minute" work into a single afternoon.
  4. Record the gap. Whether you skip or catch up, emit a metric or a log line: job X missed 72 ticks, we skipped or we ran a catch-up from timestamp A to B. The next person should not have to infer it from a quiet graph.

The dangerous recovery is the one that looks like a healthy scheduler: every missed send, retry and rebuild suddenly starts at once. delay.run gives each HTTP job a schedule, retries and a run log, so you can see what actually fired after a gap — and you can set the retry behaviour on purpose, rather than inheriting a catch-up surprise.

The parts I'm still unsure about

  • Kubernetes startingDeadlineSeconds. A short deadline means "skip if we missed the window". A long one means "run it anyway, once". That is a third option: catch up one missed tick, not all of them. I think this is the right default for "run a report at 09:00" and the wrong default for "every five minutes, consume a queue". I still see teams copy 100 or 3600 without saying which job they think they have.
  • Overlapping catch-up and the next real tick. If a catch-up is still running when the next wall-clock slot arrives, do you skip the slot, queue it, or run both? A lock plus "skip if already running" is the only version I trust, and it has to be tested.
  • Human-triggered "run the missed ones". I like this for billing and reports: the scheduler skips, and a button (or a one-off job) runs the catch-up with a visible range. I do not like it as the only path if the team will not be at the desk when the scheduler returns at 3 a.m.

If you have not picked a policy, you already have one: it is whatever your current tool does when Persistent is true, or when startingDeadlineSeconds is unset. That is the policy you should read before the next outage, not after.

Related reading

After your last scheduler outage, did the jobs catch up, skip, or do something you only noticed because a customer was emailed twice? Which policy do you want the next time?

Top comments (1)

Collapse
 
smtahosin profile image
S M Tahosin •

Skip for me lol. Box died 4 hours, catch-up fired 61 runs in 9 minutes at a rate-limited API.. I watched the logs. Sends though, never catch those up :D