Job queue

On this page 7

A job queue is a persistent list of units of background work, called jobs, waiting to be processed by workers. In scheduling and automation, it decouples the moment a task is created from the moment it is executed, so that applications can hand off slow or unreliable work such as sending emails, generating reports or calling external APIs, and respond to users immediately.

Each job typically contains a type, a payload of input data and metadata such as priority, attempt count and scheduled time. A broker or database stores the jobs, and one or more worker processes fetch, execute and acknowledge them, with failed jobs retried or moved aside according to policy.

How a job queue processes work

A job queue processes work through a cycle of enqueue, reserve, execute and acknowledge. A producer adds a job; a worker reserves it so that no other worker takes it; the worker runs the job; and on success it acknowledges completion, which removes the job from the queue.

Reservation is protected by a visibility timeout or lease. If a worker crashes or exceeds the lease, typically from 30 seconds to several minutes, the job becomes visible again and another worker picks it up. This mechanism prevents lost work but means a job may run more than once.

StateMeaningNext transitions
WaitingReady and available to workersActive
DelayedScheduled for a future timeWaiting when the time arrives
ActiveReserved and being executedCompleted, failed or back to waiting
CompletedFinished successfullyRemoved or archived
FailedExhausted retries or rejectedDead letter queue or manual retry
Job lifecycle states

Storage backends vary. In-memory stores such as Redis-based queues offer low latency, dedicated message brokers offer routing and durability features, and database-backed queues keep jobs in the same transaction as application data, which simplifies consistency at moderate volumes.

Key job queue parameters

The behavior of a job queue is shaped by a handful of parameters that trade throughput, latency and safety. Defaults rarely fit every job type, so production systems tune them per queue.

ParameterTypical rangeEffect
Worker concurrency1 to hundreds per processMore parallelism, more load on dependencies
Visibility timeout30 seconds to 12 hoursToo short causes duplicates, too long delays recovery
Maximum attempts3 to 25Balances persistence against wasted work
Retry backoffSeconds to hours, often exponentialGives failing dependencies time to recover
Priority levels2 to 10Urgent jobs bypass bulk work
Retention of finished jobsHours to weeksDebugging history versus storage use
Important configuration parameters

Ordering deserves special attention. Most job queues offer approximately first-in, first-out delivery, not strict ordering, because parallel workers and retries reorder execution. When order matters, for example for updates to one account, jobs are grouped by a partition or group key so that one worker handles each key sequentially.

A job queue stores and distributes work, while neighboring concepts decide when work is created or who executes it. Clear separation of these roles keeps background processing understandable.

ConceptRoleRelation to a job queue
Job queueHolds pending work durablyThe central buffer
WorkerProcess that executes jobsConsumes jobs from the queue
Task schedulerCreates jobs at planned timesFeeds the queue on a schedule
Delayed jobJob with a future run timeA queue feature, not a separate system
Job retryRe-execution after failurePolicy applied by the queue or worker
Message queueGeneral transport of messages between servicesOften the underlying technology
Job queue and neighboring terms

The difference between a job queue and a message queue is mostly one of intent. A message queue transports events that consumers interpret freely, while a job queue carries explicit commands to perform work, with built-in concepts such as attempts, progress, results and delayed execution.

Designing jobs and workers

Well-designed jobs are small, idempotent and self-describing. Because any job may run twice, it must produce the same final effect when repeated, for example by checking whether an email was already sent or by using an idempotency key with an external API.

  • Pass identifiers, not large objects, and load current data inside the job.
  • Split long tasks into smaller jobs so that progress survives restarts.
  • Separate queues by workload, keeping quick user-facing jobs away from slow bulk jobs.
  • Shut workers down gracefully, finishing or releasing active jobs before exit.
  • Monitor queue depth and job age, which reveal backlogs before users notice.

Scaling usually means adding workers until a downstream limit is reached, such as database connections or an external API rate limit. Beyond that point, more workers only add errors, so concurrency should be capped by the slowest dependency.

Common job queue problems

Most job queue incidents involve duplicates, backlogs or poison jobs. The table below maps frequent symptoms to causes and fixes.

SymptomLikely causeFix
Duplicate side effectsLease expired during a slow jobIdempotent jobs and longer or extended leases
Growing backlogWorkers slower than incoming rateScale workers or reduce job cost
Same job fails foreverPoison payload or permanent errorAttempt limit and dead letter queue
Urgent jobs waitShared queue with bulk workSeparate queues or priorities
Jobs lost on deployWorkers killed mid-executionGraceful shutdown and acknowledgments
Symptoms, causes and fixes

Understanding it simply

A job queue works like the order rail in a busy restaurant kitchen. Waiters pin up tickets and go back to the guests, and the cooks take the next ticket whenever they are free.

Nobody has to wait at the counter while a dish is prepared, and if one cook leaves mid-shift, the ticket goes back on the rail for someone else. The kitchen just has to make sure the same dish is not served twice.

Applied in practice

An event ticketing platform sends a PDF ticket and a confirmation email after each purchase. Generating the PDF and calling the email provider took several seconds, and during popular sales checkout pages timed out.

The team moves this work into a job queue. Checkout now enqueues one job with the order identifier and responds immediately. Twenty workers generate tickets and send emails, with up to five attempts and exponential backoff when the email provider is slow. Each job records a sent flag, so a retried job never sends a second email.

During the next major sale, the queue absorbed a backlog of tens of thousands of jobs, checkout stayed fast, and every ticket was delivered within minutes.