Background Jobs & Queues

Difficulty
Importance

The problem

Some work (sending an email, processing an uploaded video) takes too long to do while a user's HTTP request waits for a response — background jobs let a server respond immediately and complete the slow work separately, tracked through a queue instead of blocking the request.

Why now

Stacks and queues already established the FIFO structure this pattern depends on; interprocess communication already showed that separate processes can communicate through a shared channel. A job queue is exactly that combination — a queue-based channel between the fast, request-handling process and a separate, slower worker process.

Mental model

Instead of doing slow work inline, a request handler pushes a description of the work onto a queue and immediately responds 'accepted' — a separate worker process pulls jobs off that same queue whenever it's free and does the actual work, completely decoupled in time from the original request. This is the queue data structure doing exactly what it's for: preserving order while letting production and consumption happen at different, independent rates.

Requires

Unlocks

Used in

Projects

  • Build a simple job queue (even an in-memory array-backed one) where an HTTP endpoint enqueues a job and a separate worker loop processes it asynchronously
  • Add retry logic to a background job that fails intermittently, with a maximum retry count before it's marked permanently failed

Examples

  • A signup endpoint responds immediately with 201 Created and enqueues a 'send welcome email' job rather than waiting on a slow email API mid-request
  • A video upload endpoint returns instantly while a background worker transcodes the video separately, updating status the client can poll

Resources

Mastery checklist