Persistent
Set up and run your first Pulsar queue using a persistent runtime environment.
Quick Start: Persistent Runtime
Learn how to initialize storage drivers, define queues, and start the Pulsar engine in a persistent runtime environment (Node.js, Bun, Docker, or long-running servers).
Import Pulsar Core and Storage Modules
Import the main Pulsar engine along with the required storage drivers and unified storage abstractions.
import { Pulsar, PulsarRuntime } from "pulsar";
import { PostgresDriver, PulsarUnifiedStorage, RedisDriver } from "pulsar/storage";
import { createQueue } from "pulsar";Initialize Storage and Drivers
Configure your primary PostgreSQL driver and an optional Redis cache driver. Combine them using PulsarUnifiedStorage.
// Optional: Redis cache driver for ultra-low latency caching
const cacheStorage = new RedisDriver({
protocol: "tcp",
keyPrefix: "pulsar",
connectionString: "127.0.0.1:6379",
});
// Required: PostgreSQL driver for persistent state and message queue storage
const postgresDriver = new PostgresDriver({
connectionString: "postgresql://postgres:password@localhost:5432/postgres",
unloggedTableSchema: "pulsar_engine",
});
// Combine drivers into unified storage
const unifiedStorage = new PulsarUnifiedStorage({
cache: cacheStorage,
db: postgresDriver,
strategy: "AUTO",
});Redis is Optional
Redis caching is optional. To learn more about how caching strategies work, see the Unified Storage System documentation.
Define Your Queues
Create your queue configurations inside a dedicated queue file (e.g., queue.ts).
import { createQueue } from "pulsar";
export const Queue1 = createQueue({
queue: "q_1",
type: "STANDARD",
concurrency: 10,
cycleTickLimit: 10,
maxJobsPerTick: 1000,
n: 10,
sleep: 10,
// Preset options: REALTIME | STANDARD | RELAXED | ULTRA_EFFICIENT | BALANCED | CUSTOM
profile: {
activePollMs: 100,
backoffPollMs: 100,
maxTimerMs: 500,
idlePollMs: 100,
},
// Pooler options: interval-driven-pooler (IDP) | event-driven-pooler (EDP)
pooler: "interval-driven-pooler",
consumer: {
type: "http",
url: "http://localhost:9999/test-f",
headers: {
Authorization: `Bearer ${process.env.SUPABASE_ANON_KEY}`,
},
},
});For full options and parameter descriptions, check the Queue Configurations guide.
Initialize and Launch the Engine
Instantiate Pulsar passing your runtime type, storage, queues, swarm config, and engine configuration.
const engine = new Pulsar({
runtime: PulsarRuntime.PERSISTENT,
storage: unifiedStorage,
queues: [Queue1, Queue2, Queue3],
swarmConfig: {
maxGlobalConcurrency: 1000,
globalMaxJobsPerTick: 100_000,
},
engine: {
selfURL: "[http://host.docker.internal:9999/process-job](http://host.docker.internal:9999/process-job)",
selfInvocationMethod: "auto_using_pgnet",
selfInvocationIntervalSec: 5,
healthCheckIntervalSec: 15,
cycleTickLimit: 1000,
tickConcurrency: "sequential",
lockKey: "pulsar:lock:idp",
instanceId: crypto.randomUUID(),
},
});
// Boot up the engine processing cycle
await engine.start();For full options and parameter descriptions, check the Engine Configurations guide.