Queen MQ
Use cases

Patterns and recipes built on Queen.

Queen on its own is a partitioned message broker. The same queen-mq npm package also ships a fluent stream-processing SDK — windows, joins, stateful reducers, and gates — that runs in your own Node process and commits state, sink emissions, and source acks atomically in PostgreSQL. The pages below are end-to-end recipes that combine the broker with the streaming SDK to solve real production problems.

Each card below links to a dedicated page with code you can copy-paste and numbers from real verified runs against a live Queen server.

Canonical recipes

Live · backpressure

Rate limiter for external APIs

Throttle outbound calls to OTAs, LLM providers, or any third-party API with a token-bucket gate. Per-key state, FIFO order on retries, no deferred queue, scales linearly with multiple stream consumers.

.gate(tokenBucketGate({ capacity, refillPerSec, costFn }))
stress-tested: 9,431 msg/sec, 500k events, 0 errors
Live · ops

Subscription replay

Rewind a brand-new consumer group to any timestamp and reprocess just that window — without disturbing the production consumer. Each CG has its own offset row in PostgreSQL, so production and replay run truly independently.

.group('reprocess').subscriptionFrom('2026-05-11T14:00:00Z')
verified: 1,500 events, replay CG hits exact idx 500 boundary
Live · orchestration

Transactional multi-stage pipelines

Chain multiple processing stages — translate → route → notify — with one PG transaction per handoff. A worker crash between stages cannot duplicate or drop a message. Per-stage retries and DLQ are built in.

.transaction().ack(msg).queue('next').push([out]).commit()
verified: 100 in → 86 through → 14 in DLQ (0 lost, 0 duplicated)
Live · analytics

Real-time per-entity aggregations

Maintain rolling per-customer count / sum / max / avg over tumbling windows. State is a row in queen_streams.state — your Grafana, Metabase, or BI tool queries it as plain SQL. No Materialize, no ksqlDB, no extra database.

.windowTumbling({ seconds: 60 }).aggregate({ count, sum, max })
verified: 3,000 events / 30 customers, Σ matches input exactly
Live · integration

Webhook deduplication

Drop duplicate webhook deliveries from Stripe, Booking, Octorate, or Twilio without operating Redis. The per-window seen-set lives in PostgreSQL and is garbage-collected automatically when the window closes — no TTL job, no eviction policy.

.windowTumbling({ seconds: 600 }).reduce(seenSet)
verified: 1,000 unique through, 0 duplicates leaked (23.1% dropped)

A pattern you'd like to see?

These pages are written from real production code — not idealised examples. Each card above includes verified numbers from a live run against localhost:6632. If you have built something on Queen + streams that fits a generalisable pattern, please open an issue at github.com/queen-mq/queen with a short description and we'll add a recipe page for it.