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

Every job runner has to answer the same question: what happens after the third, or thirtieth, failure? I have worked on systems that retried until the dependency came back (and then fired a week of piled-up emails in two minutes), systems that stopped after five attempts (and quietly never issued an invoice), and systems with a dead-letter queue that nobody opened until a customer asked where their export was.

All three policies are defensible. They are not interchangeable, and a single global default is usually wrong.

Let's argue about it.

The case for retrying until it works

Many failures are the other side being down. A payment API, a mail provider, your own database during a failover: the job is fine, the world is not. If you give up after five tries in fifteen minutes, you have turned a vendor incident into lost work. A long backoff (minutes, then hours) almost always succeeds on its own.

"At least once" is the promise a lot of jobs make. Invoices, password resets, webhooks you already acknowledged: the work has to happen. Stopping is a quiet correctness bug.

Humans are worse at retries than loops are. A person who has to re-run last night's billing is going to miss a row, or run it twice. If the job is idempotent, leaving it in the retry loop is safer than handing it to a tired operator.

The case for stopping after N attempts

Not every failure is transient. A payload that does not validate, a user who no longer exists, a 401 because a token was revoked: retrying those is how you get a tight loop, a large bill, and a vendor that disables you. A cap is a circuit breaker.

Unbounded retries become a surprise traffic spike. When the provider comes back, every delayed job wakes up at once. I would rather have a cap and a report than a self-inflicted DDoS on a recovering dependency.

Some work has a deadline. A reminder for a meeting that already happened, a same-day delivery dispatch, a 2FA code: late is wrong. Retrying for a day is not persistence, it is a bug.

A cap forces you to think. If you have to pick N, you also have to pick what happens next, even if "what happens next" is an alert. Forever is how that decision gets postponed forever.

The case for a dead-letter queue (DLQ)

It keeps the payload. A hard stop that only increments a counter leaves you with no easy way to replay. A DLQ is the missed work, in a place you can inspect, fix, and re-run.

It separates "this job is poison" from "this job is late". Poison messages (bad payloads, code bugs on a particular shape) should not block the rest of the queue. A DLQ is that isolation.

It is an honest backlog. A retry loop hides the pile inside "in progress". A DLQ makes the pile visible, which is the only way a team will staff draining it.

The argument against a DLQ is the obvious one: if no one drains it, you have built a more expensive floor to drop work onto, plus the comfort of thinking you didn't drop it.

Where I've landed

I want a mix, per job, written down:

  1. Retry with backoff, with a cap, for almost everything. The cap is in time as well as attempts: for example, eight attempts over 24 hours, not eight attempts in two minutes.
  2. Give up earlier when the work has a deadline, or when the error is clearly permanent (a 400 you have classified, a missing record, a signature that will never match).
  3. Land in a DLQ after the cap, with an alert on queue depth, not only on each failure. A weekly "DLQ is empty" check is as useful as the queue itself.
  4. Classify errors. A 429 or 503 retries; a 400 with invalid_account does not. A generic 500 retries, because you cannot trust every vendor to use status codes well, but a parser error in your code should go to the DLQ immediately. Otherwise you retry a poison payload up to the cap on every occurrence.
  5. Make replay a first-class action, with the same idempotency the original job had. A DLQ you cannot safely replay is a folder of regret.

Retries only help if you can see every attempt, and if the handler is safe to run again. delay.run retries a failed HTTP job with backoff and keeps a log of every run, so a temporary outage is handled by the schedule, and a job that has given up is visible instead of silent.

The parts I'm still unsure about

  • Who is allowed to drain the DLQ. Engineers only? Support, for a "please resend the invoice" button? I have seen both go wrong.
  • Whether a DLQ should auto-replay after a deploy that claims to fix the bug. Tempting, and a good way to re-run a partial fix against the whole pile.
  • Jobs that are already in a provider's retry loop (webhooks). Adding your own unbounded retries on top is how you get triple processing.

A quick experiment

Pick ten production jobs and write, for each, the current policy in one line: forever, cap of N, or DLQ. Then look at last month's failures and ask whether that policy did the right thing. The jobs where you wince are the ones to change.

Related reading

What's your default today, and which failure — a dropped invoice, a retry storm, or a DLQ nobody drained — have you already had?