← BLOG

What is a background worker?

A background worker is a process that takes slow or asynchronous work out of the user request path, usually by reading jobs from a queue.

HOW IT WORKS · 19 AUGUST 2026 · 5 MIN READ

A background worker is a long-running process that performs work outside the request that created it. The web app records a job, returns a response to the user, and a worker picks up that job from a queue or database.

This is useful when the task is too slow, unreliable, or expensive to keep a user waiting for it. Sending email, generating a PDF, resizing media, importing a large file, and calling a slow third-party API are common examples.

The parts have different jobs

PARTWHAT IT DOESHOW LONG IT RUNS
Web processAccepts the request and creates a jobContinuously, but each request should finish quickly
JobDescribes one unit of workUntil it succeeds, fails, or expires
QueueStores and hands out pending jobsDurably, outside one app process
WorkerClaims a job and performs itContinuously
Cron schedulerCreates work at a set timeWakes on a schedule or stays active in a process

A job is not a worker. The job is the instruction. The worker is the process that waits for instructions. A queue connects the process that asks for work to the process that performs it.

One order, without and with a worker

Without a worker, a checkout request might charge the card, create an invoice PDF, send two emails, update a CRM, and then respond. Any slow dependency keeps the customer staring at a spinner, and one timeout can make the whole request look failed.

  1. 01
    The API validates the orderIt performs only the work required to accept or reject the purchase.
  2. 02
    The API records jobsInvoice, email, and CRM tasks enter a durable queue with an order identifier.
  3. 03
    The customer gets a responseThe request finishes without waiting for the slow follow-up work.
  4. 04
    The worker claims each jobIt performs the task, records success, and retries failures according to policy.
  5. 05
    Exhausted work becomes visibleA dead-letter queue or failed state keeps a bad job from disappearing or retrying forever.

Worker, cron job, or serverless function

USEWHEN THE WORK BEGINSBEST FIT
Background workerWhen a queue or event has workContinuous processing and low pickup delay
Cron jobAt a known timeReports, cleanup, and periodic synchronization
Serverless functionWhen a request or event invokes itBursty, short, stateless work
Workflow engineAcross several dependent stepsLong processes with retries, waits, and branching

A worker can also own a schedule, but that does not make every scheduled task a queue. Likewise, a function can consume a queue without staying alive between messages. The useful distinction is who owns the waiting and where unfinished work survives.

Reliability comes from the queue contract

  • A job remains available if a worker crashes before acknowledging it.
  • Retries have a limit and delay, rather than an immediate infinite loop.
  • The handler is idempotent, so processing the same job twice is safe.
  • Long jobs expose progress or a heartbeat.
  • Failed jobs remain inspectable instead of being deleted.
  • Queue depth and oldest-job age are monitored.

Many queues provide at-least-once delivery rather than a promise that code runs exactly once. That is why idempotency belongs in the application. Use a stable job or business identifier to detect a repeated attempt.

What the worker needs from hosting

A worker does not need a public port when it only connects outward to Redis, RabbitMQ, a database, or an API. It does need a process that stays awake, restarts after a crash, receives shutdown signals, and exposes logs. Local disk should be treated as temporary unless the host explicitly guarantees persistence.

Spocket can run the Node or Python worker process, but it does not include the queue or database. Bring that connection string as an environment variable. The /run/workers page covers the runtime, while /blog/serverless-vs-always-on helps if the job volume is bursty enough that a function may cost less.

Need somewhere to put it?

Spocket runs apps, workers and scrapers that have to stay awake. Deploy from Claude or Cursor by asking, from $3/mo. First app is free for 7 days, no card.

Background worker hostingRead the quickstart
Spocket
BlogDocsTermsPrivacyHome