Platformatic Job Queue supports three storage backends, each optimized for different use cases: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.
- MemoryStorage: In-memory storage for development and testing
- RedisStorage: Production-ready storage using Redis or Valkey
- FileStorage: Filesystem-based storage for single-node deployments
Storage Interface
All storage backends implement theStorage interface defined in src/storage/types.ts. This ensures consistent behavior across different backends.
Core Operations
Every storage backend must support:- Queue operations: enqueue, dequeue, requeue, ack
- Job state management: getJobState, setJobState, deleteJob
- Result storage: setResult, getResult, setError, getError
- Worker tracking: registerWorker, unregisterWorker, getWorkers
- Notifications: subscribeToJob, notifyJobComplete, publishEvent
- Atomic operations: completeJob, failJob, retryJob
MemoryStorage
In-memory storage using JavaScript data structures. Ideal for development, testing, and single-process scenarios.Characteristics
Data Persistence: None - all data is lost when the process exits
Concurrency: Single process only - does not support multiple workers across processes
Performance: Fastest option - no I/O overhead, all operations in memory
Implementation Details
Internal structures (fromsrc/storage/memory.ts:22):
Blocking Dequeue
MemoryStorage implements blocking dequeue using promises:TTL Cleanup
A background interval cleans up expired results, errors, and workers every second:When to Use
- ✅ Unit tests and integration tests
- ✅ Local development
- ✅ Simple single-process applications
- ❌ Production deployments
- ❌ Multi-worker setups
- ❌ Data persistence requirements
RedisStorage
Production-ready storage using Redis 7+ or Valkey 8+. Supports distributed workers, atomic operations, and real-time notifications.Configuration
Redis connection URL. Can also be set via
REDIS_URL environment variable.Prefix for all Redis keys. Useful for namespacing multiple queues in the same Redis instance.
Optional Pino logger for debugging Redis operations.
Characteristics
Data Persistence: Durable - survives process restarts (depends on Redis persistence configuration)
Concurrency: Fully distributed - supports multiple workers across processes and servers
Performance: High throughput with atomic Lua scripts and blocking operations
Redis Key Structure
With default prefixjq::
jq:queue- Main job queue (LIST)jq:processing:<workerId>- Per-worker processing queue (LIST)jq:jobs- Job states (HASH: id → state)jq:results- Job results with TTL (HASH: id → result)jq:errors- Job errors with TTL (HASH: id → error)jq:workers- Active workers (HASH: workerId → timestamp)jq:notify:<jobId>- Job notification channels (PUBSUB)jq:events- Job state change events (PUBSUB)jq:reaper:lock- Reaper leader election lock (STRING)
Atomic Operations with Lua Scripts
RedisStorage uses Lua scripts for atomic multi-key operations. Scripts are loaded once at connection time:redis-scripts/ directory):
enqueue.lua- Atomically check for duplicates and enqueuecomplete.lua- Mark job as completed, store result, remove from processing queuefail.lua- Mark job as failed, store error, remove from processing queueretry.lua- Update attempts and requeue failed jobcancel.lua- Delete job if not processingrenew-leader-lock.lua- Renew Reaper leader lockrelease-leader-lock.lua- Release Reaper leader lock
Blocking Dequeue
RedisStorage usesBLMOVE for efficient blocking dequeue:
TTL Implementation
Results and errors are stored with an 8-byte header containing the expiry timestamp:Pub/Sub for Real-Time Notifications
RedisStorage maintains a dedicated subscriber client for notifications:Connection Management
RedisStorage maintains three Redis connections:When to Use
- ✅ Production deployments
- ✅ Distributed worker systems
- ✅ High-throughput workloads
- ✅ Multi-server deployments
- ✅ Need for data persistence
- ✅ Request/response patterns with
enqueueAndWait() - ❌ Serverless environments (connection overhead)
- ❌ Edge computing scenarios
FileStorage
Filesystem-based storage using atomic file operations. Suitable for single-node deployments where Redis is not available.Configuration
Directory path for storing queue data. Must be writable by the process.
Characteristics
Data Persistence: Durable - all data persists to disk
Concurrency: Single filesystem - works across processes on the same machine, but not across servers
Performance: Slower than Redis due to disk I/O, but faster than remote Redis with high latency
Directory Structure
FileStorage creates the following directory structure:FIFO Ordering with Sequence Numbers
Jobs are enqueued with monotonic sequence numbers for strict FIFO ordering:Atomic Operations
FileStorage usesfast-write-atomic for atomic writes:
rename() to claim jobs:
File Watching for Notifications
FileStorage usesfs.watch() for real-time notifications:
TTL Cleanup with Leader Election
Multiple FileStorage instances on the same filesystem elect a leader to perform TTL cleanup:When to Use
- ✅ Single-server deployments
- ✅ No Redis infrastructure
- ✅ Need data persistence
- ✅ Moderate throughput requirements
- ✅ Shared filesystem access (NFS, EFS)
- ❌ High-throughput workloads (> 1000 jobs/sec)
- ❌ Multi-server deployments without shared storage
- ❌ Need for distributed locking
Performance Comparison
| Backend | Throughput | Latency | Persistence | Distributed | Setup |
|---|---|---|---|---|---|
| MemoryStorage | Highest | Lowest | None | No | None |
| RedisStorage | High | Low | Durable | Yes | Redis/Valkey |
| FileStorage | Moderate | Medium | Durable | Single FS | Directory |
Switching Between Backends
You can easily switch backends by changing the storage configuration:Custom Storage Backends
You can implement custom storage backends by implementing theStorage interface:
src/storage/types.ts for the complete interface definition.
Related Concepts
- Queue Architecture - Understanding the Queue class
- Deduplication - How job IDs prevent duplicates
- Reaper - Stalled job recovery across storage backends