Skip to content

Background and scheduled jobs

Introduction

Move slow or scheduled work off the user request—run it in the background, or trigger it on a schedule.

Why use it

  • Sending email, generating reports, processing images, and calling slow third-party APIs take time and should not occupy the user’s request, or it will time out — see Timeouts and retries.
  • Reconciliation, cleanup, and statistical rollups need to run automatically on a schedule.
  • Failures should be able to retry automatically and leave a record.

How to do it

Two kinds of needs:

  1. Fire-and-forget jobs: the request puts the job on a queue, and a dedicated “worker process” picks it up and runs it. The underlying store is usually a message queue, Redis, or a database.
  2. Scheduled jobs: triggered by a cron expression (for example, “every day at 3:00”).

Component comparison

Hangfire

Self-hosted open sourceOpen sourceOpsLow

The most popular background job library in C#: it stores "run later" and "run on schedule" jobs in a database and comes with a web dashboard.

Best forRoutine background work in C# projects such as sending emails, generating reports and scheduled cleanups.

Avoid whenThe project is on a Python stack, or the job is so simple that a script running once a day will do.

Pros

A few lines of code add background jobs, delayed jobs, and scheduled jobs

The built-in dashboard shows success, failure, and retries

Failures retry automatically, and jobs stored in the database are not lost

Cons

Jobs land in the database, so a large volume needs a look at performance

You must authorize the dashboard yourself, or it is left exposed

It supports only .NET, so a Python project cannot use it

Official docs ↗

Quartz.NET

Self-hosted open sourceOpen sourceOpsLow

A scheduling-oriented job library for C#, good at triggering jobs on complex time rules (such as the last business day of each month).

Best forC# projects with complex scheduling rules that are mainly timer-based.

Avoid whenA simple need to "run a job in the background after a request ends" with a dashboard.

Pros

Expressive time rules, supporting cron expressions and calendar exclusions

Can store scheduling info in a database and supports multi-instance clustering

Highly controllable, suited to complex scheduling

Cons

No management dashboard by default; to see job status you must build one or read logs

More configuration options than Hangfire, so it is easy to misconfigure

It mainly solves "trigger on time"; failure retries and one-off background jobs you must write yourself

Official docs ↗

BackgroundService (built into .NET)

Built into the frameworkOpsLow

The background service mechanism built into .NET: a loop starts along with the program and does work on a schedule inside the application process.

Best forLightweight jobs in small single-machine projects, such as periodically clearing a cache or polling a status.

Avoid whenJobs must never be lost or duplicated (such as charging money), or you need to deploy multiple servers.

Pros

No extra library to install; zero additional dependencies

Intuitive to write, suited to very simple loop jobs

Lives and dies with the application, adding no new component to deployment

Cons

Jobs are not persisted; work in progress is lost if the program restarts or crashes

With multiple servers each one runs it, so duplicate execution is likely

No dashboard or retry mechanism; you must write them yourself

Celery

Self-hosted open sourceOpen sourceOpsMedium

The most commonly used task queue in Python: the app hands jobs to a message broker, and separately started "worker" processes pick them up and run them.

Best forPython projects needing reliable background jobs and scheduled jobs, with a medium or higher job volume.

Avoid whenOnly one or two very simple scheduled jobs, or you do not want to deploy an extra message broker.

Pros

Delay, schedules, retries, and task routing are all included

It can be paired with Django, Flask, and FastAPI

Worker processes can be scaled on their own and do not slow the site

Cons

You also have to deploy a message broker and the worker processes

There are many settings, and a lost or duplicated job is hard to trace

There is no dashboard by default, so viewing status needs another tool

Official docs ↗

APScheduler

Self-hosted open sourceOpen sourceOpsLow

A lightweight Python scheduling library: set in your program "run this function every so often / at a certain time of day".

Best forScheduled jobs in single-machine or small projects, such as daily summaries and periodic sync.

Avoid whenThe site runs multiple processes or servers, or needs lots of async jobs.

Pros

One Python library is enough; you do not need a message queue beside it

A few lines of code are enough to write the rules for when a job runs

Cron-style time expressions are supported for those schedules

Cons

By default it runs only in this process, so extra copies repeat the job

It does not suit handing a large pile of one-off tasks to workers

Whether jobs remain after a restart depends on whether they are persisted

Official docs ↗

ARQ / RQ

Self-hosted open sourceOpen sourceOpsLow

A lightweight Redis-based task queue, simpler than Celery and good enough for many needs.

Best forPython projects that already have Redis and whose job needs are not complex.

Avoid whenYou need complex job orchestration or support for several message brokers.

Pros

Simple setup, quicker to learn than Celery

Uses Redis as the queue, so nothing new to install if you already have Redis

Small codebase, easier to read when something goes wrong

Cons

Less full-featured than Celery; complex routing and scheduling must be added yourself

Depends on Redis, and Redis data loss affects unprocessed jobs

Smaller community and fewer resources than Celery

Official docs ↗

System scheduled tasks (cron + scripts)

Hand-rolledOpsLow

Have the server's operating system run a script or command on a schedule, independent of any application framework.

Best forSmall fixed-time jobs such as daily backups, cleaning old files and generating daily reports.

Avoid whenBackground jobs triggered by user actions, or when you need reliable retries and monitoring.

Pros

The simplest option: built into the server, nothing new to install

Jobs are independent of the web application, so one crashing does not affect the other

Language-agnostic, usable by both C# and Python projects

Cons

No failure retries and no job history page; on errors you can only check the logs yourself

With multiple servers you must make sure only one runs it

Can only trigger by time, not "handle later after a user clicks"

BullMQ

Open-source libraryOpen sourceOpsMedium

A Redis-based job queue for Node.js: delayed jobs, retries, repeatable jobs, and concurrency control.

Best forAsync jobs such as sending emails, exports, and third-party calls.

Avoid whenThere are only a handful of scheduled tasks (system cron or a platform scheduler is simpler).

Pros

Full-featured: delay, retry, rate limiting, priority, repeatable jobs

TypeScript-friendly with an active community

Standalone worker processes can scale horizontally

Cons

Depends on Redis; losing Redis data loses jobs

You must deploy and monitor the worker processes yourself

Jobs must be written to be idempotent

Official docs ↗

tokio-cron-scheduler

Open-source libraryOpen sourceOpsLow

Runs scheduled work on the Tokio runtime using cron expressions.

Best forScheduled tasks, report generation, and expired-data cleanup.

Avoid whenYou need to absorb large bursts of async jobs (use a message queue).

Pros

Same runtime as Tokio, so no separate scheduler process

Cron expressions are easy to read

Fits light jobs such as reports and expiry cleanup

Cons

Every instance runs the job unless you add a distributed lock or pin scheduling to one instance

In-memory job state is lost on restart

Not a message queue, so it is unsuited to high-throughput async work

Official docs ↗

asynq

Open-source libraryOpen sourceOpsMedium

A Redis-based job queue for Go: retries, delays, priorities, and a web monitoring dashboard.

Best forAsync jobs such as sending emails, exports, and third-party calls.

Avoid whenJob enqueueing must be strongly consistent with a database transaction (consider a Postgres-based queue).

Pros

Clean API with retries and delays out of the box

Official monitoring dashboard and CLI

Workers scale out easily

Cons

Depends on Redis

Jobs must be idempotent

Cannot be atomically bound to Postgres transactions (needs the outbox pattern)

Official docs ↗

Checklist

  • Jobs are idempotent, so retries and duplicate runs are safe
  • Retry count and intervals are configured, with an alert on final failure
  • Scheduled jobs do not fire more than once under multi-instance deploy
  • Job arguments pass IDs rather than large objects; load fresh data when the job runs
  • Worker processes are deployed and scaled separately from the web process
  • Job execution has logs and duration records — see Logging