{
  "id": 8213400,
  "title": "Polling versus events for Node background work",
  "url": "https://urgent.news/2026/09/18/polling-versus-events-for-node-background-work",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-09-18T09:08:56.000Z",
  "source": {
    "name": "Dev.to",
    "slug": "dev-to",
    "url": "https://dev.to/yaseenyk04/polling-versus-events-for-node-background-work-5hk9"
  },
  "original_language": "en",
  "account": "SetInterval schedules background work by start time, which can cause jobs to overlap and pile up when a task takes longer than its interval. This leads to a growing overlap until the pool of resources is exhausted. To address this issue, use setTimeout instead, creating a gap between runs instead of a strict schedule. However, polling still has downsides: each idle check costs a query, round trip, and wake-up, which can add up quickly, especially on metered databases or battery-powered systems. Events, on the other hand, remove the idle cost but add the responsibility of handling delivery guarantees. Missed notifications result in jobs that never run, creating a reputation for occasional failures. The recommended approach is to use both methods, leveraging events for latency and a slow poll as a safety net. Each background worker should start with setInterval to check for tasks, but also include a slow poll for reliability. Implement safe concurrent execution by using a draining flag to prevent overlapping tasks. This layered approach provides the benefits of both methods, ensuring low latency, minimal idle cost, and reliable job execution without the risk of silent failures.",
  "summary": "[ EXECUTIVE TEARDOWN // TL;DR ] setInterval schedules by start time, so a job slower than its interval overlaps itself and piles up; chain setTimeout instead. A poll that finds nothing still costs a query, a round trip and a wake-up, multiplied by every instance you run. Events remove the idle cost but add delivery guarantees you now own; a missed notification is a job that never runs. The…",
  "key_points": [
    "SetInterval can cause overlapping tasks and exhaust resources",
    "setTimeout creates gaps between runs to prevent overlap",
    "Combine events with polling for latency and reliability"
  ],
  "editors_take": null,
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "ai_generated": true,
  "disclaimer": "Summaries, key points and the editor’s take are written by software from other outlets’ reporting and may contain errors — always check the linked original."
}