Pulsar
open sourcePostgreSQL·PGMQ·serverless · edge · servers

Multi-runtime pooler engine for PGMQ

Pulsar is the execution engine for PGMQ. It decides when to wake, how much to pull, who does the work and how to keep going, on serverless functions, edge isolates or your own servers.

Run your first queue →
live runticking
run 1 · 10 ticks · cycleTickLimitself-invoke

Every bar is a tick. When the tick budget or the host's clock runs out, Pulsar stops cleanly and hands off to a fresh run, so a serverless time limit never drops a job.

01What it is

PGMQ stores the messages. Pulsar operates them.

Pulsar is an orchestration engine, not a queue. You keep your Postgres and your business logic. Pulsar runs everything in between.

L4
Your code
Consumers and handlers
L3
Pulsar
The orchestration layer: ticks, locks, dispatch
L2
PGMQ
Stores and manages the messages
L1
PostgreSQL
Durable foundation
+ Pulsar handles
  • +When to wake and when to stay quiet
  • +How much work to pull each tick
  • +Per-queue and global concurrency
  • +Distributed locks and worker slots
  • +Retries and failure recovery
  • +Clean handoff across serverless invocations
− Pulsar is not
  • −A message queue or broker
  • −A replacement for PGMQ
  • −A home for your business logic
02Poolers

Choose what wakes the engine, per queue

An interval-driven queue is polled on a schedule under one shared lock. An event-driven queue sleeps until a database trigger fires, then drains itself and goes quiet. One insert burst does not mean one invocation per job.

interval-drivenwakes every interval, work or not
event-drivensilent until a job is inserted
PoolerTriggerIdle costPickup latencyBest for
interval-driven-poolerTimed pollingLow, regular pollsBound by the intervalContinuous, batch and delayed work
event-driven-poolerStorage eventZero idle pollsUnder 10msBursty, sporadic, interactive tasks

Interval-driven is the default. Polling cadence comes from the queue's profile.

realtime1
Tightest polling for latency-sensitive work
fast2
Frequent polls, low pickup delay
balanced3
A sensible default for most queues
relaxed4
Fewer polls, gentler on the database
background5
Long intervals for batch and delayed jobs
03Features

Everything between the queues and your code

The moving parts of a production queue, already built and configured per queue.

Per-queue configuration

Concurrency, batch size, tick limits, timing profile and consumer, tuned separately for every queue in the same engine.

Runtime-aware engine

An internal clock tracks the time your host has left and stops ticking before the platform ends the function, then hands off cleanly.

  1. 01Reliable by constructionDistributed locks, retries and failure recovery prevent races and duplicate processing.
  2. 02Elastic scalingWorkers wake on a trigger or an interval, so nothing idles waiting for jobs.
  3. 03Dispatch anywhereHTTP endpoints, async handlers, or streams into Kafka, NATS and other brokers.
  4. 04Deeply customizableHooks, payload transformations, queue routing and event triggers are yours to shape.

Two levels of control

The engine sets how Pulsar lives and what it may spend. Every queue then sets its own pace inside those limits.

Engine

Runtime, storage, self-invocation, global concurrency and the tick budget.

new Pulsar({ engine })
const pulsar = new Pulsar({
  engine: {
    runtime: "edge-isolate",
    storage: { cache: upstash },
    selfInvocation: { mode: "pg_net", intervalSec: 1 },
    maxGlobalConcurrency: 100,
    cycleTickLimit: 10,
    tickConcurrency: "sequential",
  },
});
Queue

Pooler, polling profile, concurrency, batch size and consumer.

createQueue({ … })
pulsar.createQueue({
  name: "scrape",
  pooler: "event-driven",
  profile: "balanced",
  concurrency: 10,
  n: 10,
  maxJobsPerTick: 100,
  consumer: { type: "http", url: process.env.WORKER_URL },
});
Read the full configuration reference →
04The tick

One loop runs everything: the tick

A tick is one complete execution cycle. Ticks repeat until a queue or engine cycleTickLimit is spent, or the host's clock runs low. Then the run ends and a fresh one begins.

tick
01/ 10
1 of 10 ticks used
  1. 1
    Evaluate limits
    Read queue config, tick limits and the host clock.
  2. 2
    Size the batch
    Work out how much can run inside the budget.
  3. 3
    Pull from PGMQ
    Claim a batch of jobs from the queue.
  4. 4
    Dispatch
    Send each job to its configured consumer.
  5. 5
    Update state
    Record workers, slots and locks.
  6. 6
    Decide
    Run another tick, or stop and hand off.
tick budget for this runcycleTickLimit = 10
05Tuning

Do the math before production does

Requested jobs are concurrency × n. If that exceeds maxJobsPerTick, Pulsar scales workers down for the tick instead of overloading your database. Self-invocation cost is just arithmetic.

01 · per-tick batch
concurrency × n
50 × 10 = 500 requested → 200 fetched · workers scaled down
02 · self-invocation cost
per 30 days
2,592,000
invocations per 30-day month while running continuously. Raise the interval to trade pickup latency for fewer invocations.
03 · global concurrency
100 / 100 slots
demand 1000 vs 100 slots → each queue gets 10
04 · tick concurrency

Sequential is safe on CPU, memory and connections. Queues take turns inside the tick budget. With a cycleTickLimit of 10 across 10 queues: each queue gets about 1 tick.

Global concurrency

With maxGlobalConcurrency at 100 and ten queues each asking for 100 workers, every queue is held to about 10. Slots are first come, first served when demand is lower.

Tick concurrency

Sequential is safe on CPU, memory and connections. Parallel ticks every queue at once for lower latency, at the price of spikes. With a cycleTickLimit of 10 across 10 queues, sequential gives each queue one tick.

06Runtimes

One engine, three ways to live

Set the runtime and Pulsar adapts its scheduling and lifecycle. Pick one to watch how a run ends.

V8_ISOLATE
selected runtime

Tracks the invocation window and the isolate's age. Pauses briefly before self-invoking so the platform can recycle the old isolate.

Cloudflare WorkersSupabase Edge FunctionsDeno Deploy
selfURL
Required
cycleTickLimit
10, max 20
Restarts itself
Yes, after a short pause
Re-invocation uses pg_net by default. Choose manual to trigger the next cycle yourself through something fire-and-forget like QStash or SNS. Never await a request to selfURL, it holds the current instance open.
07Storage

Postgres is enough. Redis makes it faster.

Unified Storage puts Redis and PostgreSQL behind one interface. Supply a cache driver and hot operations move to Redis. Leave it out and they run through an unlogged Postgres table.

Add a Redis cache driver
Optional. Flip it to see where the engine's hot operations go.
engine operations
Worker registrationPostgres unlogged
Worker deregistrationPostgres unlogged
Execution statePostgres unlogged
Distributed locksPostgres unlogged
Slot accountingPostgres unlogged
Redis

Not connected. Nothing breaks without it.

PostgreSQL

Always the persistent layer. Handles all of the hot operations on the left.

hot operations on Postgres5 of 5

Unlogged tables skip write-ahead logging, so they are truncated after a database crash. That only affects the engine's operational state, not your PGMQ queues.

08Integrations

Plug jobs into anything

Pulsar claims the jobs, then dispatches them to your own endpoint, your own function, or the streaming tools you already run.

dispatch
claimed jobs → target
PulsarHTTP endpointclaimed jobs
HTTP endpoint consumer
consumer: {
  type: "http",
  url: "https://api.example.com/jobs/scrape",
  headers: { authorization: "Bearer ..." },
}
09Compatibility

Runs on the Postgres you already have

Pulsar works with most Postgres databases, including serverless ones like NeonDB. If your database can run the required extensions, you're set.

supported databases
postgresql
NeonDB logo
NeonDB
Serverless Postgres
Supabase logo
Supabase
Managed Postgres
Amazon RDS logo
Amazon RDS
AWS managed database
Google Cloud SQL logo
Google Cloud SQL
Google Cloud managed database
Azure Database logo
Azure Database
Microsoft Azure managed database
Self-hosted logo
Self-hosted
Docker, VM or bare metal
Works with any PostgreSQL database as long as you can setup pgmq+ more
09Auhtor

Built by one person, in two months.

Pulsar is a small project made with care, not a claim to be perfect. It is not a replacement for SQS and it is not built for a million requests per second. If it helps you, that's wonderful, and if you'd like to make it better, contributions are very welcome.

maintainer
open source · 2 months
Portrait of Mohammed Hamim
Creator & maintainer

Mohammed Hamim

Pulsar started as a personal itch and grew into something I'm proud of. Issues, ideas and pull requests are all appreciated.

Give your queues an engine.