Pulsar

Storage

Your first document

Pulsar Unified Storage manages low-latency memory stores (Redis) and relational PostgreSQL database instances under a single interface.

By decoupling storage strategies from engine execution logic, Pulsar lets you dynamically balance throughput speed and data durability depending on your target runtime environment (Serverless, V8 Isolates, or Persistent Node.js/Deno processes).

In AUTO mode, Pulsar automatically delegates high-frequency queue operations to Redis if a cache driver is supplied, falling back to fast PostgreSQL Unlogged Tables when Redis is omitted.


Setup & Code Example

pulsar-storage.ts
import { Pulsar, PulsarRuntime, PulsarUnifiedStorage } from '@pulsar/core';
import { RedisDriver } from '@pulsar/redis';
import { PostgresDriver } from '@pulsar/postgres';

// 1. Configure the in-memory cache layer (Redis via TCP or HTTP)
const cacheStorage = new RedisDriver({
  protocol: "tcp",
  keyPrefix: "pulsar",
  connectionString: "127.0.0.1:6379",
});

// 2. Configure the persistent database layer (PostgreSQL)
const postgresDriver = new PostgresDriver({
  connectionString: "postgresql://postgres:password@localhost:5432/postgres",
  unloggedTableSchema: "pulsar_engine",
});

// 3. Initialize the Unified Storage orchestrator
const unifiedStorage = new PulsarUnifiedStorage({
  cache: cacheStorage,
  db: postgresDriver,
  strategy: "AUTO",
});

// 4. Mount Unified Storage onto the Pulsar Engine instance
const engine = new Pulsar({
  runtime: PulsarRuntime.PERSISTENT,
  storage: unifiedStorage,
});

API Reference & Options

PulsarUnifiedStorage Options

PulsarUnifiedStorage coordinates connection lifecycles, health checks, and operation dispatch across cache and database drivers.

ParameterTypeRequired?DefaultDescription
dbPostgresDriverYes—Instance of the PostgreSQL storage driver for relational state, lock coordination, and fallback queueing.
cacheRedisDriverNoundefinedOptional instance of RedisDriver. Used as the primary operational store when strategy includes Redis.
strategyStorageStrategyNo"AUTO"Determines how job operations and state syncing are split between cache and db.

RedisDriver Configuration

The RedisDriver supports both stateful TCP connections (ideal for EC2, Docker, or Kubernetes) and stateless HTTP/REST requests (optimized for Cloudflare Workers, Supabase Edge, and serverless functions).

1. TCP Protocol Options (protocol: "tcp")

ParameterTypeRequired?DefaultDescription
protocol"tcp"Yes—Explicitly selects TCP socket transport.
connectionStringstringYes—Redis URI formatted as redis://[user]:[password]@[host]:[port].
keyPrefixstringNo"pulsar"Namespace prefix added to all Redis keys to isolate tenant or environment queues.

2. HTTP / REST Protocol Options (protocol: "http")

ParameterTypeRequired?DefaultDescription
protocol"http"Yes—Explicitly selects stateless HTTP/REST requests (e.g., Upstash Redis API).
urlstringYes—The HTTP endpoint URL for the Redis REST REST API provider.
tokenstringYes—Bearer authentication token for authorization.
keyPrefixstringNo"pulsar"Namespace prefix added to all Redis keys.

PostgresDriver Configuration

The PostgresDriver interfaces directly with PostgreSQL to manage relational engine state, advisory locks, and PGMQ queues.

ParameterTypeRequired?DefaultDescription
connectionStringstringYes—PostgreSQL connection URI (postgresql://user:pass@host:5432/dbname).
unloggedTableSchemastringNo"pulsar_engine"Database schema used to manage high-speed unlogged volatile queue tables.
maxConnectionsnumberNo10Maximum pool size for concurrent database connections.
idleTimeoutMsnumberNo30000Time in milliseconds an idle connection remains open before being released.
sslboolean | SSLOptionsNofalseEnable or configure TLS/SSL encryption for cloud providers (e.g., Supabase, Neon, AWS RDS).

Strategy Comparison

StrategyPrimary Queue StoreEngine Locks & MetadataIdeal Use CaseExtra Infra Required?
AUTORedis (if present) / PG UnloggedPostgreSQLStandard default for mixed serverless and server environments.❌ Optional
REDIS_CACHERedis RAM BufferPostgreSQLUltra-high throughput microservices requiring sub-millisecond dispatch.Yes (Redis)
PG_UNLOGGEDPG Unlogged TablesPostgreSQLHigh-speed, single-database setups that want to avoid managing Redis.❌ No

Data Safety & Persistence Behavior

PostgreSQL Unlogged Tables (PG_UNLOGGED) bypass write-ahead logging (WAL) for maximum write performance. While significantly faster than standard relational tables, data stored in unlogged tables is volatile and will be truncated by PostgreSQL during an unclean shutdown or database crash.

  1. Serverless & Edge Isolates (Cloudflare Workers, Supabase Edge): Use protocol: "http" with RedisDriver and strategy "AUTO" or "REDIS_CACHE" to avoid connection pooling limits and TCP handshake latency.

  2. Persistent Container Pools (Docker, ECS, Kubernetes): Use protocol: "tcp" with RedisDriver or rely on "PG_UNLOGGED" if you prefer keeping your entire queue stack inside a single PostgreSQL database.

  3. Strict Durability Requirements: If message retention across database crashes is mandatory, combine standard PGMQ relational queues with PG_UNLOGGED fallback disabled.

On this page