# Background Job

A unit of work executed outside an interactive request so it can run later, longer, or independently.

- Type: term
- Domain: Engineering & architecture
- Level: Foundational
- Last reviewed: 2026-09-24
- Original: [Soroush’s Product Wiki](<https://wiki.soroush.uk/topic/background-job/>)

## What it means

A background job is an automated task performed without holding open the user interaction that initiated it. Jobs may be triggered by a message, schedule, state change, or operator and are processed by workers with their own capacity and retry policy. Background describes the execution relationship, not whether the work is unimportant.

## Why it matters

Moving slow work out of a request can make a product feel responsive and isolate bursty processing. It also changes the experience from immediate success to accepted work whose progress, failure, cancellation, and eventual result may need to be visible.

## When to use it

Use background jobs for email delivery, media processing, imports, reports, maintenance, and other work that can finish after the initiating request. Keep work synchronous when the user needs its result to proceed or when asynchronous infrastructure would outweigh the benefit.

## How it works

1. Define a bounded job payload, owner, expected duration, and completion outcome.
2. Persist or enqueue the job before telling the caller that work was accepted.
3. Let a worker claim the job with concurrency and resource limits.
4. Make processing safe for retries and record progress or checkpoints where useful.
5. Expose completion or failure to users and operators, including a recovery path.
6. Measure queue delay, run time, retry count, terminal failures, and business outcomes.

## A practical example

A research tool accepts a CSV import, creates a durable job, and immediately shows an import status page. A worker validates rows in batches and checkpoints progress; the user receives a summary with downloadable errors when processing completes.

## Where it breaks

Background execution adds delay, status management, worker capacity, and new failure modes. Jobs may run more than once or after their original context changed. Long-running tasks need cancellation, checkpointing, and careful deployment behavior.

## Common mistakes

- Showing success when the job was only accepted and may still fail.
- Passing ephemeral request state instead of a durable, versioned job payload.
- Retrying non-idempotent work and duplicating emails, charges, or records.
- Operating workers without backlog, age, failure, and completion monitoring.

## Visualization

[View the visualization on the website](<https://wiki.soroush.uk/topic/background-job/#visualization-background-job>)

## Sources

1. [Recommendations for Developing Background Jobs](<https://learn.microsoft.com/en-us/azure/well-architected/design-guides/background-jobs>) — Microsoft Learn · Institutional architecture guide
2. [Background Tasks with Hosted Services in ASP.NET Core](<https://learn.microsoft.com/en-us/aspnet/core/fundamentals/host/hosted-services>) — Microsoft Learn · Official technical documentation

## Related topics

- [Message Queue](<https://wiki.soroush.uk/topic/message-queue/>)
- [Synchronous and Asynchronous Processing](<https://wiki.soroush.uk/topic/synchronous-and-asynchronous-processing/>)
- [Cron Job](<https://wiki.soroush.uk/topic/cron-job/>)
