Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/platformatic/job-queue/llms.txt

Use this file to discover all available pages before exploring further.

Reliable Job Queue for Node.js

Build scalable background processing with deduplication, request/response patterns, and pluggable storage. Production-ready with TypeScript support.

Quick start

Get your first job queue running in minutes

1

Install the package

Install @platformatic/job-queue from npm:
npm install @platformatic/job-queue
2

Create a queue with storage

Choose a storage backend. For development, use MemoryStorage:
import { Queue, MemoryStorage } from '@platformatic/job-queue'

const storage = new MemoryStorage()
const queue = new Queue({
  storage,
  concurrency: 5
})
For production, use RedisStorage for distributed workloads:
import { Queue, RedisStorage } from '@platformatic/job-queue'

const storage = new RedisStorage({
  url: 'redis://localhost:6379'
})
const queue = new Queue({
  storage,
  concurrency: 10
})
3

Register a job handler

Define how your jobs are processed:
queue.execute(async (job) => {
  console.log(`Processing job ${job.id}:`, job.payload)
  
  // Your business logic here
  const result = await processEmail(job.payload.email)
  
  return { sent: true, messageId: result.id }
})
4

Start the queue and enqueue jobs

Start processing and add jobs to the queue:
await queue.start()

// Fire-and-forget
await queue.enqueue('email-1', { 
  email: 'user@example.com' 
})

// Wait for result
const result = await queue.enqueueAndWait('email-2', {
  email: 'another@example.com'
}, { timeout: 30000 })

console.log('Result:', result)
import { Queue, MemoryStorage } from '@platformatic/job-queue'

const storage = new MemoryStorage()
const queue = new Queue({
  storage,
  concurrency: 5
})

queue.execute(async (job) => {
  console.log(`Processing job ${job.id}:`, job.payload)
  return { sent: true }
})

await queue.start()

// Enqueue jobs
await queue.enqueue('email-1', { email: 'user@example.com' })

// Or wait for result
const result = await queue.enqueueAndWait('email-2', { 
  email: 'another@example.com' 
})

console.log('Result:', result)

// Graceful shutdown
await queue.stop()

Key features

Everything you need for production-grade background processing

Job deduplication

Prevent duplicate job processing with configurable result caching

Request/Response

Enqueue jobs and wait for results with enqueueAndWait()

Multiple storage backends

Redis/Valkey for distributed systems, filesystem for single-node, or in-memory for testing

Automatic retries

Configurable retry attempts with exponential backoff for failed jobs

Stalled job recovery

Reaper automatically recovers jobs from crashed workers

Graceful shutdown

Complete in-flight jobs before stopping for zero data loss

TypeScript native

Full type safety with generic payload and result types

Leader election

High availability with automatic failover for Reaper instances

Explore by topic

Deep dive into core concepts and advanced patterns

Queue

Understand the Queue class and configuration options

Storage backends

Compare MemoryStorage, RedisStorage, and FileStorage

Producer/Consumer

Separate job enqueuers from workers for scalability

Error handling

Handle job failures with typed errors and retries

Custom serialization

Use MessagePack or custom formats for job payloads

Reaper

Recover stalled jobs and ensure reliability

Ready to build?

Start processing background jobs with confidence. Check out the quickstart guide or explore the full API reference.