termEngineering & architecture

Background Job

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

Download Markdown (.md)

01What 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.[1][2]

Durable work outside the user request Accept the job, process it independently, then expose its outcome
  1. 01TriggerUser, schedule, state change, operator
  2. 02Persist jobPayload, identity, owner, status
  3. 03Worker claimsCapacity and concurrency limits
  4. 04Process safelyRetries, idempotency, checkpoints
  5. 05Complete or failUser visibility and recovery path

The initiating interaction should not claim acceptance until the job is durably persisted or enqueued.

02Why 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.

03When 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.

04How 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.

05A practical example

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.

06Where 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.

07Sources

  1. Recommendations for Developing Background JobsMicrosoft Learn · Institutional architecture guideRecommendations for Developing Background Jobs
  2. Background Tasks with Hosted Services in ASP.NET CoreMicrosoft Learn · Official technical documentationBackground Tasks with Hosted Services in ASP.NET Core
View saved topics

Start typing to search titles, definitions, categories, and frameworks.