Ordering
A key-ordered queue delivers each routing key's messages one at a time, in the order they were sent.
A key-ordered queue delivers the messages of one routing key in the order they were sent, with at most one of them out with a worker at a time. Different keys do not wait for each other, so many keys are processed in parallel. Use it when one key's messages must be handled in order, such as the changes to one account.
Here account-7 has three messages waiting, open, deposit, and close, and account-8 has one. A claim for ten messages returns one per key:
curl -s -X POST 'localhost:8080/v1/queues/apps/transfers/claims?max=10&wait=5s' \
| jq -c '.claims[] | {routing_key, body, attempt}'{"routing_key":"account-7","body":"open","attempt":1}
{"routing_key":"account-8","body":"open","attempt":1}Once the worker acks account-7's open, the next claim returns its deposit:
{"routing_key":"account-7","body":"deposit","attempt":1}The order rule
Order is per routing key, in the order the messages were stored. One send stores its messages in the order given. Two sends for the same key are ordered by which one was stored first. Messages sent without a routing key have no order among themselves and never wait.
You choose the kind when you create the queue, and it never changes. A key-ordered queue has a few rules of its own:
| Setting or feature | On a key-ordered queue |
|---|---|
key_concurrency | Always 1. Nova stores 1 whatever an update names. |
| Delayed delivery | A send that sets a delay is refused with 400 and "reason": "delay_on_key_ordered" |
concurrency | Works as on a standard queue: it caps claims across all keys |
A failed message blocks its key
When a message fails an attempt, it stays first in its key and is delivered again after its wait. The key's later messages wait behind it, while other keys go on. When the last attempt fails, or a worker nacks the message as terminal, Nova moves it to the dead-letter stream and the key goes on with its next message.
One failing message holds up its key
With the default retry policy, a message that cannot be processed stops its key for five attempts. The waits between them are 1, 2, 4, and 8 seconds, plus each attempt's work or claim TTL. A large max_attempts or a long wait holds the key longer. Nack such a message as terminal as soon as the worker knows it cannot succeed.
If the range moves to another node during a wait, the new node delivers the waiting message at once.
Order across a split
A queue stores its messages in ranges, as a scalable stream does, and a busy range can split in two. The original range stops taking new messages, and two new ranges divide its routing keys. On a key-ordered queue, a new range delivers nothing until the original range has delivered every message it holds and all of them are settled. A key's older messages are therefore done before its newer ones.
The wait covers the whole new range. If one message in the original range is stuck, every key in the new ranges waits. That is another reason to keep max_attempts and the waits small.
The original range is delivered to its end only while a worker takes messages from the node that delivers it. The SDK workers connect to every node that delivers the queue, and one-shot claims reach every node. A worker you write yourself, without an SDK, must do the same.
When a range splits to give a noisy key its own range, the new ranges without that key start once the original range has finished every other key. The noisy key's own range waits until the original range is finished.
What order does not cover
Delivery is still at least once. With memory claims, a node failure can deliver again a message a worker already holds, so two workers briefly hold messages of the same key. With persisted claims, the new node keeps the key held until the claim is settled or expires.
A range move, as in a rolling restart, can also overlap a key's messages in either claims mode. For a short time, 100 to 250 ms in tests, the old node can deliver a key's next message. A worker of the new node may still hold the message before it. Do not rely on one message per key at a time for correctness while ranges move. When a message is delivered twice lists every case.