Urgent.News

What's breaking now, across thousands of outlets.

Tech

Webhook Follow-Up Task Scheduling: One Hour Later with Queues or Cron Explained

Webhook Follow-Up Scheduling: Delayed Messages vs Per-Event Timers Explained Short answer: for a logistics webhook that must run about an hour later, put a durable due time in a queue-backed table and let a bounded worker claim it; use a cron sweep as the recovery path, not one timer per event. This keeps latency visible while a rate-limited pool drains at a controlled cost. Imagine a carrier…

When scheduling a webhook follow-up task to run approximately one hour later, using a durable delayed queue or per-event cron entry are two common approaches. However, each has its own set of advantages and drawbacks.

For a logistics webhook requiring an hourly delay, it is recommended to store the event ID, action, intended run time, attempt count, and a deduplication key in a single transaction alongside the business update. This ensures the follow-up task is recorded in a durable state. The webhook can then return a success response to the carrier without performing the slow follow-up immediately.

To implement this, create a `FollowUp` table with fields for event ID, kind, runAt timestamp, attempts, and dedupeKey. A poller can then claim ready rows using short batches, leveraging PostgreSQL's `FOR UPDATE SKIP LOCKED` to prevent concurrent workers from claiming the same row. The actual task should be executed outside the database transaction to avoid blocking the transaction.

Implement a claimReady function to retrieve ready rows based on the desired batch size. This function should consider factors such as queue age, claim duration, downstream response time, retry count, and the number of ready rows. Logging should include the webhook ID and dedupe key to trace a delivery across retries.

When comparing delayed message queues and cron sweeps, delayed queues offer convenience through built-in retry and visibility settings managed by the broker. However, they also introduce operational dependencies such as retention and ordering rules. In contrast, a cron sweep over a due-time table provides greater inspectability, allowing operators to query late rows, replay events, or change leases without relying on broker-specific consoles. The trade-off is the added latency from polling.

Per-event timers are the simplest to code but lack durability, making them suitable only for single-process utilities where missing a follow-up is not critical. They are not ideal for scenarios requiring auditability, frequent deployments, or multiple replicas receiving the same webhook.

To handle failures gracefully, treat the worker as a control loop that discovers ready work, admits it based on the downstream limit, executes it idempotently, and records the next state. Implement a semaphore around the carrier call to control concurrency. A drain loop can manage the worker, releasing permits as calls complete and leaving remaining rows in the ready state.

Monitor metrics such as age at execution, queue age, retry counts, and retries-to-completions ratio to ensure the system is running smoothly and to prevent overload scenarios.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

Why your n8n Gmail Trigger is not working (and how to fix it)

You connected Gmail. The node is green in the editor. Then production stays quiet—or every poll returns nothing—while new mail sits in the inbox.

  • Workflow must be published and active, not draft
  • Self-hosted n8n needs Google Cloud OAuth client with Gmail API enabled
  • Check filters, poll interval, and downstream nodes for failures

Wabi's features, in plain language: threads, mini-apps, widgets and shared chats

I'm the author of Wabi Wiki, an unofficial guide to the Wabi AI assistant — not affiliated with Wabi. If you only open Wabi when you have a question, you may miss how it is meant to be used day to…

  • Wabi AI offers threads for organizing conversations by topic or project
  • Mini-apps in Wabi 2.0 are self-contained tools for specific tasks
  • Widgets allow quick access to threads and mini-apps on iOS/Android home screens

More from Tuesday 3 November →