Queues on streams
How a queue delivers the records of a scalable stream to workers, and how little state that takes.
A queue gives each message to one worker at a time and delivers it again until a worker acknowledges it. Inside, a queue is a scalable stream whose records are the messages, plus a small amount of delivery state for each range. The messages are stored and retained exactly like any other records. What a queue adds is the part that decides who works on what.
The parts
| Part | What it does |
|---|---|
| Queue stream | A scalable stream that holds the messages. Its retention age is the message TTL. |
| Dispatcher | The part of every node that delivers queue ranges. Each node's dispatcher takes a share of all ranges. |
| Dispatcher ring | The membership that splits the ranges among the nodes' dispatchers |
| Seat | One range's delivery on one node: it reads the range and deals its messages to workers |
| Ready window | The messages a seat has read and not yet settled, ready or claimed. A message is settled when a worker acks it, or when the seat moves a failed attempt out of the range, for a later retry or to the dead-letter stream. |
| Claim | One message out with one worker, until a deadline |
| Ack frontier | The range's lowest position that is not yet settled. Everything below it is done. |
| Due key | A metadata row that holds a failed message until its retry, or until it moves to the dead-letter stream |
How a message is delivered
- A sender's message is appended to the queue's stream. Its routing key chooses the range, as on any scalable stream.
- A worker opens a work session on the nodes that deliver the queue's ranges. On each node, a seat opens for each range of the queue in that node's share.
- The seat reads its range from the saved ack frontier and keeps the messages in its ready window.
- It deals messages to the workers as claims, as far as each worker's credit allows.
- An ack settles the message. The seat moves the ack frontier past every settled position and saves it.
- A nack, or a claim that reaches its deadline, fails the attempt. On a standard queue the seat writes a due key and settles the position. When the wait is over, it appends the message to the queue again with the next attempt number. After the last attempt, it appends the message to the dead-letter stream instead.
Messages stay in the stream
The messages are records, and a retry is a new record. Nova never edits a message where it is stored. Everything else a queue keeps is small:
| Data | Where |
|---|---|
| Messages | Records of the queue's scalable stream, in object storage |
| That the stream is a queue, and its range map | The stream's own row in the metadata store |
| Queue settings | One row per queue, in the dispatch keyspace |
| Delivery progress | One state row per range: its ack frontier, and a bitmap of the positions settled above it |
| Retries, delays, and pending dead letters | Due keys under the range |
| Claims, with persisted claims | One row per claim, naming its worker |
| Idempotent sends, with durable dedup | One row per idempotency key |
A queue's delivery state lives in its own dispatch keyspace. It changes with every message, so it is kept apart from stream metadata and from the auditor's due-queues.
Because messages are records, queues need no write path, failover, or retention of their own. A retry that appends the message again lets the ack frontier move past the failed position at once, so one failing message does not hold back the range. On a key-ordered queue the seat keeps a failed message in place instead and retries it there, because an append would put it behind its key's later messages. Only its last attempt leaves the range, for the dead-letter stream. See Ordering.
The ack frontier
Workers ack out of order, so a seat keeps the positions settled above the frontier as a bitmap beside it.
position 0 1 2 3 4 5 6 7 8 9 10 11
settled x x x x . x x . . x . .
^ ack frontier = 4, bitmap marks 5, 6, 9The seat saves the frontier and bitmap with one compare-and-set every 250 ms, sooner after 1,024 settled positions, and once more when it closes. A seat that takes over a range starts reading at the saved frontier and skips the positions the bitmap marks. It needs nothing else to recover.
The cost of saving progress in batches is a small window of repeats. With memory claims, the default, a node failure delivers again the messages that were out with workers, plus those acknowledged in the last 250 ms, at most 1,024. Delivery is therefore at least once, and every delivery carries the message's id so that a worker can recognize a repeat. With persisted claims, each claim is a row, and a node that takes over a range honors the claims still out. See When a message is delivered twice.
The dispatcher ring
Each node's dispatcher joins the dispatcher ring with a membership record tied to its metadata store session. The ring assigns each of 1,024 dispatch shards to one node by rendezvous hashing, and each range belongs to the shard its id hashes to. A node that drains leaves the ring. A node that dies leaves it when its session expires, 10 to 15 seconds later.
Every 5 seconds, a dispatcher reads the ring and a small set of change rows, and nothing else. The cost of an idle pass therefore does not grow with the number of queues. When a node gains a shard, it starts delivering the ranges filed under it for the queues that have workers connected there. When it loses one, it closes those seats in order. A worker learns of the move at its session's next refresh, within 5 seconds.
While the ring changes, two nodes can briefly both believe they own a shard. Both may deliver the same messages for that moment. Seats guard their state rows with an epoch, so the older seat learns it was replaced at its next save and stops.
Seats run only while needed
A node keeps state for a queue only while a work session or one-shot claim of that queue is open on it. A seat opens when its range is needed and closes after 60 seconds idle, unless it still holds claims. A queue with no workers costs nothing on any node beyond its stored rows.
A seat's ready window holds an entry per message, not the message body: its position, size, routing key, and the fields the seat deals by. It reads records in batches and fetches the bodies again just before it deals them. Each seat may use up to 8 MiB of window, and all seats on a node share a budget of 512 MiB. At its limit a seat stops reading until workers settle messages. A slow queue therefore cannot take a node's memory.
Key-ordered queues and splits
On a key-ordered queue, a range created by a split or a merge delivers nothing until each of its parent ranges has delivered and settled every message. Until then its seat checks the parents' state rows every second. A key's older messages are therefore always done before its newer ones, even when the key moved to another range.
How long isolation takes
A noisy key, one routing key that fills a range, slows every key sharing that range. A seat counts the bytes in its window by routing hash. When the window is full and one hash holds more than half of it, the seat asks for a split at that hash, which gives the key a range of its own. Isolation is not immediate:
| Step | Waits for |
|---|---|
| The seat notices | Its read has been held by a full window for 10 seconds, then its next progress save |
| The split is made | The auditor's next check of its due-queues, every 30 seconds. A range less than a minute old also waits out its split cooldown. |
| The delivering node learns of the split | Its next 5 second pass. Until then it keeps delivering what it had read, which on a flooded range is mostly the flood. |
Meanwhile the seat still takes turns among keys over the messages it has read. A queue isolates at most 16 keys, and a split that would pass that number, or the stream's 256 range cap, is refused and logged. Keys that share one 32-bit hash are noisy together, and messages without a key are never isolated.
The old range is then delivered in two passes: first the other keys, then the noisy key. A message of the noisy key that a worker held when the range closed, or that was acknowledged out of order before it closed, can be delivered again. The number of such repeats is bounded by the claims in progress when the range closed.
When a node fails
A node failure loses no message, because the messages are records in object storage. It costs delivery time. When the node's session expires, the ring gives its shards to other nodes. Their seats start each range from its saved ack frontier. With memory claims they deal again every message that was out with a worker, and with persisted claims they wait for those claims to end. Workers reconnect to the new nodes at their next refresh. A failed message's due key survives in the metadata store, so its retry still happens on time.
Go deeper
Dispatch and windows
News rows, seats, the ready window, and the window budget
Persisted claims
Claim rows, and what a new seat does with them
Seat lifecycle and crash safety
Idle seats, due keys, purges, and durable dedup
Work sessions
The frames between a worker and a node
Back to the concepts: Queues and Delivery and claims.