← All posts

A scheduler only rings: HTTP delivery belongs in the queue

A timer says when to start. Retries, duplicates, and dead letters live in the queue and the receiver, not inside the scheduled script.

A scheduler only rings: HTTP delivery belongs in the queue
Contents

In brief

An alarm at 3 a.m. does not remember whether anyone signed for the parcel. A scheduler is the same kind of device. It says when to start. It does not say whether the HTTP call arrived.

The author builds CLIs and SDKs and counts every piece of glue around the first useful call. A five-line scheduler that loses a delivery on the first network timeout is not small. It is unfinished.

A scheduled script that calls the network should create durable work and return. Retries and duplicate handling stay outside the timer. Delivery guarantees decide the design. A low price and a checkbox that says "can send HTTP" do not.

What happened

The piece starts from a nightly media cleanup. The job removes stale files, updates an index, and tells another service. Retrying inside the cron process is the wrong place for that. Enqueue the work. Make each outbound call safe to repeat.

A scheduler can offer a trigger window. The outbound request needs its own contract. Four questions: what is being delivered, how many attempts are allowed, how a duplicate is recognized, and where a permanently failing item goes.

The smallest useful model is at-least-once delivery plus a stable idempotency key. The sender records the event before sending it. A worker claims it, sends the request, and marks success only after an acceptable response.

Then comes the gap no scheduler label can close. The process dies after the receiver has committed and before the sender records success. The next attempt sends the same request again. That gap is normal. The receiver has to make the repeat harmless.

Exactly-once sounds cleaner. Across two systems joined by HTTP it is usually an argument about names, unless both sides share a transaction boundary. The author would rather state what a duplicate does than hide it behind the product's label.

In the example the event carries a stable id. That is the deduplication key, not a timestamp and not a hash of fields that may still change. It stays the same across retries. The sample kind is media.cleanup.completed. The body holds a library id and how many files were removed. Status values are pending, delivered, and dead, plus an attempt count and the next attempt time.

The receiver can store that id with the side effect. Or it can reject a key it has already seen, before it performs the side effect again.

The scheduled function creates work. It does not perform all of it. The sample only enqueues one event and returns. One test checks enqueueing, another the delivery behavior, a third the dead-letter path. That is less glue than retries, logging, and the schedule stuffed into one process.

Sort the outcome by status, instead of treating every non-success as the same problem. A 200–299 marks the event delivered. A 400–499 goes to the dead letter: a bad body is not repaired by waiting. A timeout might be.

Then a ceiling. In the example the fifth failure also moves the event to dead, with a reason. Otherwise the delay is the minimum of 60 seconds and 2 to the power of the attempt count, in seconds. Those numbers illustrate a policy. They are not universal defaults. Without a ceiling and without state on disk, what you have is a feeling of control.

An attempt count that lives only in process memory resets when the worker restarts.

Why it matters

Price and "it can send HTTP" are quick filters. Delivery semantics decide the architecture.

A Kubernetes CronJob is good at starting work on a schedule and at saying whether two runs may overlap. It does not, by itself, turn a request into a delivery record that outlives the process. The application still needs a store, a way to classify failures, and a place to look at what never left. That fits a team that already runs the cluster. It is a poor fit when the only need is one durable outbound event.

Cloud Tasks hides dispatch behind a queue-shaped interface. The useful split is between creating the task and performing the HTTP call. Receiver idempotency, body versions, authentication, and a terminal failure stay application choices.

SQS with a dead-letter queue gives operators a place to inspect messages that exhausted their attempts. That is different from dropping the event quietly and from retrying forever. The dead-letter record should keep the event id, who the receiver was, the attempt history, and why it stopped.

Zapier, n8n, and GitHub Actions sit on different shelves. Zapier is configured hops between other people's apps. n8n can run on your own machines, and the steps are visible. GitHub Actions is tied to repository workflows and fits a scheduled script that belongs to a delivery pipeline. A checkbox labeled HTTP sorts them worse than the shelf does.

None of them removes duplicate handling at the receiver.

Before choosing, the author would run one failure. The receiver accepts the request. Kill the worker before it writes success. Start it again and look. If the system cannot explain the duplicate, the media cleanup is not ready for that setup.

At higher volume, split scheduling, dispatch, and receipt confirmation. Add a body version before the first breaking schema change. Rotate the endpoint credentials without changing the event's identity. Cap concurrent calls per receiver so a backlog does not become a burst. Make an operator replay a separate action with a trail. An automatic retry means the system is still following policy. A replay means a person sent a finished event again. Mixing those verbs makes the later incident review harder.

In practice

Ship only after the failures, not after one clean 200. The interesting gap sits between the receiver's commit and the sender's success write. You will not see it until a process dies in the middle.

In every row below the sender still has the event waiting. What changes is the behavior you require.

What broke What should happen
The network wait ran out Retry with a bounded pause
The receiver returned a validation error Dead-letter queue and an alert
The receiver committed, the sender crashed Retry the same key
The worker restarted during the pause Read the next attempt time from storage
Attempts ran out Keep the body and the reason it stopped

Then test the schedule itself. A missed run should be visible. A long cleanup should not overlap the next one unless overlap is intentional. Clock drift and a daylight-saving change deserve a test when the schedule is in local time. The cleanup data may be boring. The clock is not.

Log a correlation id, the delivery id, the attempt number, the response code, how long it took, and the final state. Leave the full media body out of the logs by default. Charts should show how old a waiting event is, the retry count, the dead-letter count, and delivery latency. An "the process is up" alert says little. An old event still waiting is the problem a person will notice.

Measure three stretches. From the timer firing to a durable enqueue. From the queue to the request leaving. Recovery after a process you killed on purpose. One clean 200 does not make the system reliable.

A one-off internal script may not need the extra parts. A queue, a store, charts, and a dead-letter routine weigh more than one scheduled HTTP call. Cleanup is different once files are already gone, the index is updated, and the neighboring service has not been told. A crash leaves them disagreeing about what happened. The next run may repeat the event. An operator investigating may send it again.

  1. Pick the lightest scheduler that can create durable work.
  2. Keep the event key stable across attempts.
  3. Send 400–499 to the dead letter. Retry a network drop until you hit the ceiling.
  4. Store the next attempt time on disk, not in process memory.
  5. Make an operator replay separate from an automatic retry, and keep a trail.

Takeaway

Leave the scheduler as an alarm. Do not throw out the parcel log if the call deletes files or updates an index. Same if it touches billing or publishes something. Losing the line between "started" and "delivered" costs more than the extra parts.

Duplicates will happen. The rule is short. The lightest timer that can create durable work, then the guarantees in the queue and in the receiver's contract. The alarm rings. A reliable outbound call behaves like a log with a receipt number.

Comments

Loading comments…