QueenMQ 2.8
QueenMQ, a kernel for distributed systems. Most examples start from Kafka; RabbitMQ and SQS join where they differ.
The plan
One hotel booking, booking-9137, goes through every chapter. Click a row to jump there.
Brokers move messages very well. What happens to one message, and around it, is yours to build.
Architecture · three nodes each
__consumer_offsets.Kafka spreads partition leaders over the nodes, so writes use all three. QueenMQ has one leader per tenant: more tenants (raft groups) spread the leaders.
Chapter 1 of 8
In Kafka a partition is a shard you size up front. In QueenMQ it is the thing you work on: one booking, one customer, one conversation.
queue bookings
Each booking is a partition: an ordered list of its events.
1.1 · Today, on Kafka
hash(key) % 4. Here booking-9137 and booking-4410 land in partition 2.1.2 · QueenMQ
// once, before the first push: name every option await queen.queue('bookings').config({ leaseTime: 30, retryLimit: 5, retryDelay: 5000, dedupWindowSeconds: 86400, retentionEnabled: true, retentionSeconds: 604800, }).create() // then: one partition per booking await queen.queue('bookings') .partition('booking-9137') .push([{ data: { event: 'created' } }])
1.3 · QueenMQ
await queen.queue('bookings') .partition('booking-9137') .push([{ transactionId: 'booking-9137-created', data: { event: 'created' } }])
transactionId in the same partition, within dedupWindowSeconds (3600 s by default, 7 days at most), writes nothing.HTTP answers 201 even when an item is refused. Read each item's status: queued, duplicate or error.
Chapter 2 of 8
Kafka gives a group one offset per partition. QueenMQ gives every message a lease, an answer, retries and a dead-letter queue, in the broker.
queue bookings · group confirm
Every message: a lease, an answer, and a place to go when it keeps failing.
2.1 · Today, on Kafka
// KafkaJS: you commit a position, not an answer const c = kafka.consumer({ groupId: 'confirm' }) await c.subscribe({ topics: ['bookings'] }) await c.run({ autoCommit: false, eachMessage: async (m) => { await confirm(m.message) // throw: blocks const n = BigInt(m.message.offset) + 1n await c.commitOffsets([{ topic: m.topic, partition: m.partition, offset: `${n}` }]) }, })
2.2 · QueenMQ
await queen.queue('bookings') .group('confirm') .each() .consume(async (msg) => { await confirm(msg.data) // throw = failed }) // return = completed
leaseTime (30 s). A worker that dies: the lease runs out, another worker gets it, and no retry is spent.failed answer: the message comes back after retryDelay (5 s), and only its booking waits.retryLimit failures (5), it goes to the dead-letter queue with its error, and the booking moves on.retry (no retry spent) and dlq (now).2.3 · QueenMQ
await queen.queue('bookings') .group('confirm') .batch(100) // messages per pop .partitions(10) // bookings per pop .concurrency(4) // handlers at once .renewLease(true, 10000) .each() .consume(confirm)
.partitions(N): one pop drains up to N bookings, each one still in order.batch and partitions out, and the broker sizes every pop (autopilot)..renewLease(true, 10000) keeps the lease while a long handler runs..partition('booking-9137') pops one booking only.2.4 · QueenMQ
// a new group can start in the past await queen.queue('bookings') .group('audit') .subscriptionFrom('2026-11-10T10:00:00Z') .consume(audit) // a group that exists moves with a seek await queen.admin.seekConsumerGroup( 'confirm', 'bookings', { timestamp: '2026-11-10T10:00:00Z' }) // { toEnd: true }: skip all it has not read
A new group starts at the end (new), like auto.offset.reset=latest. .subscriptionMode('all') reads the history; .subscriptionFrom(time) starts at a time.
Chapter 3 of 8
Confirming a booking is several writes: its state, the next event, the ack. In QueenMQ they are one log entry, all of them or none.
bookings · booking-9137 #3 · group confirmbookings/booking-9137 = confirmedemails · booking-9137 · confirm-mailpayment-reminders · booking-9137 · 15 minOne call commits all four, or none of them.
3.1 · Today, on Kafka
3.2 · QueenMQ
.consume(async (msg) => { const id = msg.partition // booking-9137 await queen.transaction() .ack(msg, 'completed', { consumerGroup: 'confirm' }) .kv.put('bookings', id, { status: 'confirmed' }, { ttl: '30d' }) .queue('emails').partition(id) .push([{ transactionId: `mail-${id}`, data: { id } }]) .commit() })
3.3 · QueenMQ
const id = 'booking-9137' const b = await queen.kv.get('bookings', id) // { found, value, version: 3 } const r = await queen.kv.put('bookings', id, { status: 'checked-in' }, { ttl: '30d', expect: b.version }) r.applied // false if someone wrote since await queen.kv.incr('quota', 'hotel-7', 1, { max: 500, ttl: '1d' })
ttl, or forever.expect makes a write depend on it.applied: false and the current value. It is not an error.Chapter 4 of 8
"Remind the guest in 15 minutes if they have not paid" is a message that arrives later. In QueenMQ it is a timer, written by the step that wants it.
timer payment-reminders / booking-9137
The timer fires as a message, in the booking's own partition.
4.1 · Today, on Kafka
4.2 · QueenMQ
// booking-9137 is created await queen.timer('payment-reminders') .key('booking-9137') .partition('booking-9137') .delay('15m') .payload({ id: 'booking-9137' }) .schedule() // 'scheduled' // the guest paid await queen.timer('payment-reminders') .key('booking-9137').cancel()
4.3 · QueenMQ
// the booking step await queen.transaction() .ack(msg, 'completed', { consumerGroup: 'bookings' }) .timer('payment-reminders').key(id) .partition(id).delay('15m') .payload({ id }).schedule() .commit() // the payment step await queen.transaction() .ack(pay, 'completed', { consumerGroup: 'payments' }) .kv.put('bookings', id, { status: 'paid' }, { ttl: '30d' }) .timer('payment-reminders').key(id).cancel() .commit()
absent on a cancel may mean the timer already fired: the reminder's handler checks the booking first.
4.4 · QueenMQ
await queen.queue('room-updates') .config({ leaseTime: 30, retryLimit: 5, retryDelay: 5000, dedupWindowSeconds: 86400, retentionEnabled: true, retentionSeconds: 604800, delayedProcessing: 300, // 5 min each windowBuffer: 3, // bursts }) .create()
delayedProcessing: every new message waits that many seconds after its push.windowBuffer: a burst waits that long, then is handed over as one batch. A delay per message is a timer.Chapter 5 of 8
Some work no message starts: the nightly report, the channel sync. A cron job on three replicas runs it three times. A lock runs it once, and a guard keeps out a holder that froze.
lock nightly-report
| holder | worker-b |
| since · until | 02:00:00 · 02:00:30, renewed |
| token | 42 |
Three replicas, one holder.
5.1 · Today, on Kafka
5.2 · QueenMQ
const lock = queen.lock('nightly-report', { ttl: '30s' }) if (!(await lock.acquire({ wait: '5s' }))) return // another worker has it try { const r = await queen.transaction() .guard(lock) // only while it is ours .queue('reports') .push([{ transactionId: 'report-11-11', data: report }]) .commit() } finally { await lock.release() }
.guard(lock) rolls its commit back.queen.semaphore(name, n): n holders. Outside QueenMQ, fence with lock.token.Chapter 6 of 8
A page wants the latest availability and a price within half a second. It does not need the history of either.
Hotel 7 · Deluxe room · tonight
| rooms left | 9 | the newest value · conflation |
| price | €129 | asked now · an ephemeral reply |
Two numbers that must be fresh, and nothing to keep.
6.1 · Today, on Kafka
6.2 · QueenMQ
await queen.queue('availability') .group('screen') .conflation(true) // the newest, per partition .partitions(64) .consume(async (msg) => { await redraw(msg.data) })
After the last push to a partition, at least one handler run starts after it.
6.3 · QueenMQ
async function quote(room) { const inbox = `inbox-${crypto.randomUUID()}` await queen.ephemeral.push('quotes', [{ room, replyTo: inbox }]) const reply = await queen.ephemeral.pop(inbox, { wait: true, timeout: 500, commitOnDelivery: true }) return reply.messages[0]?.payload ?? { room, price: null } // "ask us" }
replyTo, and waits with a timeout.6.4 · QueenMQ
| queue | ephemeral | |
|---|---|---|
| kept in | the raft log, on disk | memory of one node |
| a node crashes | nothing lost | its share is lost |
| a node stops | nothing lost | it hands its partitions over |
| transactions, DLQ, replay | yes | no |
| groups, leases, acks | yes | yes |
An answer that comes too late is worth nothing, so it does not need a disk. Anything that must survive a crash goes on a regular queue.
Chapter 7 of 8
Every push of every queue, in the order the log committed it: one feed, to ask what happened and to compute as it happens.
queen.feed()
| position | queue | partition | data |
|---|---|---|---|
| 1041 | bookings | booking-9137 | created |
| 1042 | bookings | booking-4410 | created |
| 1043 | payments | booking-9137 | paid · €387 |
| 1043 | emails | booking-9137 | confirm-mail |
| 1044 | availability | hotel-7 | 9 rooms |
One position across every queue. The pushes of one transaction share it.
7.1 · Today, on Kafka
7.2 · QueenMQ
// what happened to one booking, in the last day for await (const e of queen.feed({ partitions: ['booking-9137'], since: '1d', follow: false, })) { console.log(e.position, e.queue, e.data) } // live: every Italian booking from now on queen.feed({ queues: ['bookings'], where: [['data.country', '=', 'IT']] })
position across all queues. Nothing is leased or acked: every group still gets its messages.where is checked by the broker.7.3 · QueenMQ
await Stream .fromFeed(queen, { queues: ['bookings', 'payments'] }) .join({ sides: { booking: 'bookings', paid: 'payments' }, within: '1h', select: (got, id) => ({ id, amount: got.paid.data.amount }), onTimeout: (got, missing, id) => ({ id, missing }), }) .to(queen.queue('paid-bookings')) .run({ queryId: 'paid-bookings' })
7.4 · QueenMQ
Stream.fromFeed(queen, { queues: ['bookings', 'payments'] }) .pattern({ key: (m) => m.partition, start: (m) => m.queue === 'bookings', then: (m) => m.queue === 'payments', within: '15m', onMatch: (b) => ({ paid: b.partition }), onTimeout: (b) => ({ remind: b.partition }), }) .to(queen.queue('payment-followups')) .run({ queryId: 'payment-followups' })
.joinTable adds the latest row of a table queue to each message.7.5 · QueenMQ
await Stream .fromFeed(queen, { queues: ['availability'] }) .windowTumbling({ seconds: 60 }) .aggregate({ count: () => 1 }) .name('perMinute') .run({ queryId: 'per-minute', shards: 4 }) // anywhere else const { found, value } = await Stream .view(queen, 'per-minute') .get('perMinute', 'hotel-7')
shards: 4: four processes, each with its partitions, its position and its lock.eventTime, allowedLateness).Chapter 8 of 8
The broker streams a table into a queue, and a queue into a table. No Debezium, no Connect cluster, no consumer to write.
one HTTP call each, on the broker
Both run on every node of the cluster, with exactly-once effects.
8.1 · Today, on Kafka
Debezium Server, a process of its own, writes changes to RabbitMQ, Kinesis, Pub/Sub and others.
8.2 · QueenMQ
PUT /api/v1/connectors/bookings-src { "kind": "source", "connection": { "host": "pg", "database": "app", "user": "queen", "password": "…" }, "source": { "tables": [ { "table": "public.bookings", "queue": "bookings" } ] } }
wal_level=logical, and QUEEN_ENCRYPTION_KEY on the broker.8.3 · QueenMQ
PUT /api/v1/connectors/bookings-report { "kind": "sink", "connection": { … }, "sink": { "queue": "bookings", "table": "public.bookings_report", "mode": "upsert" } }
| append | each message is a new row |
| upsert | insert, or update the row with its key, with the columns it names |
| cdc | a source event, applied: insert, update, delete |
| sql | your statement, with parameters from the message |
8.4 · QueenMQ
The slot keeps WAL
A replication slot keeps WAL while the source is down, and can fill the database's disk. Set max_slot_wal_keep_size, and alert on queen_pg_source_slot_lag_bytes.
Every table needs a key
A primary key, or a unique index as replica identity. A table without one is refused.
A refused row
A message Postgres refuses (a constraint, a wrong type) is tried a few times, then dead-lettered with the database's error. Its partition goes on.
Key = partition
In upsert and cdc mode, keep the table's key aligned with the partition. Order holds inside a partition: two partitions writing one row would race.
In production
Not a booking we made up: a guest chat, a channel manager and a tracing service, as they run today. Names are simplified; the flows are real.
| system | it shows |
|---|---|
| guest chat | partitions · one commit per step · groups · windowBuffer · ephemeral request/reply |
| channel manager | partitions by state · conflation · timers · KV as a rate limit |
| tracing service | a stream with session windows · groups · reads by offset |
Each flow as it runs; the names are not the real ones.
In production · a guest chat
Usespartition = chat · ack + push in one transaction · a group per client · DLQ · windowBuffer · ephemeral request/reply · KV, lock, timer
LessonCarry one id through every step. A hop that drops it can only be followed by guesswork.
In production · a channel manager and Gate
Usespartition by state · ack + push + KV in one transaction · conflation · timers · ephemeral request/reply · Gate: kv.incr as the rate limit
LessonA message is a key, not a payload. A partition whose messages carried every past version kept growing.
In production · a tracing service
Usespartition = trace id · dedup by event key · a session-window stream · an archiver group · reads by offset · KV
LessonKeep big bodies out of window state: very large traces held whole in a window pushed the brokers past their memory. Since 2.7.0 QueenMQ reads state without copying it.
The end
Each box was a system to run, and a seam where a step could come apart.
The end
docker run -p 6632:6632 -p 127.0.0.1:9092:9092 \ -v /var/lib/queen:/var/lib/queen/raft \ -e QUEEN_KAFKA_EMBEDDED=true \ -e QUEEN_KAFKA_ADVERTISED_ADDR=127.0.0.1:9092 \ ghcr.io/queen-mq/queen:2.10.0
bootstrap.servers, nothing else.The end
One leader per tenant is what makes a transaction one log entry. That is the trade: a ceiling, for steps that cannot come apart.
| you are building | use |
|---|---|
| services that handle events per customer, order or booking | QueenMQ: a partition each |
| steps that must commit whole: the ack, the state, the next event, the timer | QueenMQ: one transaction |
| routing by content | QueenMQ: a router step reads, picks the queue, pushes and acks in one commit |
| only the latest value per key | QueenMQ: conflation, or KV |
| a step that needs SQL to decide | QueenMQ: query your database, commit the step with KV conditions |
| long workflows | QueenMQ: a transaction per step, KV state, timers for the waits |
| a firehose: millions of messages a second, where every millisecond counts | Kafka or Pulsar |
The end
docker run -p 6632:6632 ghcr.io/queen-mq/queen:2.10.0 npm install queen-mq
The dashboard is at localhost:6632, served by the same process.