Scalable streams inside
How a scalable stream spreads its keys over ranges, splits hot ranges, merges cold ones, and keeps each key in order.
A scalable stream is one address whose records are spread over several ranges by routing key. Each range is a stream with its own leader, so the stream's write rate grows with its number of ranges instead of stopping at one node's capacity. Records of one key stay in order, even while Nova splits a range that gets hot or merges ranges that go cold.
The parts
| Part | What it does |
|---|---|
| Range | One member of a scalable stream: an ordinary stream inside, with its own sequence numbers and leader. It is open or sealed. |
| Hash ring | The 32-bit space of routing hashes. Each open range owns one span of it, and the open ranges cover it with no overlap. |
| Range map | The stream's versioned list of ranges, with each one's span, state, parents, and router token. It lives in the stream's own row in the metadata store. |
| Routing key | The record field whose hash chooses the range |
| Router token | A token minted for each range and kept in the map. A writer must present it, which proves the writer routed with the current map. |
| Split | Seals one range and opens two or three children that divide its span |
| Merge | Seals a run of neighbouring open ranges and opens one range over their combined span |
| Bookmark | A reader's place: the map version it saw, and a position in, or the end of, each range |
How an append finds its range
- The SDK computes the routing key's hash: the low 32 bits of the key's XXH3 hash. Go and TypeScript compute the same value.
- It looks the hash up in its cached copy of the range map, which it fetched from any node. The open range whose span contains the hash takes the record.
- It sends the batch to that range's leader, with the range's router token. From here the append is an ordinary append to a stream: the write path does not read routing keys.
- If the range has been sealed, its leader refuses the batch. The SDK fetches the map again and resends to the range that now owns the hash.
An SDK append without a routing key goes whole to one range chosen at random. Over HTTP, the node or the Gateway does the routing. An HTTP append may carry records with different keys, and it is cut into one part per range. Each part is stored and acknowledged on its own, so a failure can leave some parts stored and others not. A gRPC caller without an SDK must name the range itself.
A range is an ordinary stream
Each range is a stream with its own leader, ledgers, recovery, and retention. The new parts are only the map, the routing in the client, and the jobs that split and merge.
Nova places a stream's ranges apart. Range number i of a stream goes to the i-th node of the stream's placement ranking, so a stream with four ranges usually has four different leaders. Routing happens in the client, so an append takes no extra hop through a router.
The cost is that order exists only within a range. Each range numbers its records from 0 with no gaps, and there is no stream-wide sequence number. A conditional append with a match sequence number is refused on a scalable stream, because a position belongs to one range.
Splitting a range
A split never resizes an open range. It seals the parent and creates new ranges for its span. The auditor's split job runs these steps, under a lease that allows one change per stream at a time:
Sealing the parent fixes its end: no record can be added after it. Every acknowledged record of a key is then in the parent, and every later one in a child. A producer resends its unacknowledged batches to the child in their original order, and later appends for that key wait behind them. So the key's order holds across the split. Writes to the parent's span pause only between the seal and the new map. Keys in other ranges are not affected.
Four things ask for a split:
| Trigger | When |
|---|---|
| A hot range | Its leader sees appends averaging over 100 MiB/s on Standard, or 130 MiB/s on Express, for 1 minute |
| A stranded node | A saturated node can hand none of its streams to another node, and its hottest stream is a range |
| A noisy queue key | A queue isolates one key's hash into a range of its own |
| An operator | nova stream split, at the midpoint or at a chosen hash |
A split cuts the span at its midpoint into two children. A split at a chosen hash makes three: the ranges below and above the hash, and a range that holds the hash alone. A range is not split again within 1 minute of its creation, except by an operator. A stream holds at most 256 ranges, counting sealed ones. A split that would pass the cap is refused and counted.
Cold ranges merge
When a range's leader steps down, Nova checks the range 5 minutes later. If no node leads it by then, no producer has opened it for that long. The auditor merges it with the first neighbouring range that also has no leader and is at least 5 minutes old. If the range has a leader again, the check moves an hour out, and the next time its leader steps down starts a new one.
A merge seals every range in the run and creates one range over their combined span. The new range has each sealed range as a parent. An operator can merge any run of neighbouring open ranges with nova stream merge. Merging keeps the number of open ranges in step with the load, so a stream that has gone quiet does not keep many small ranges.
Readers follow the history
A reader follows the parent links in the map. It reads a range only once every parent of that range is finished, which means read up to its sealed end, or already removed. In the diagram above, a reader takes F only after both C and E, so every key that moved into F is read in order.
A reader's bookmark saves the map version it last saw and, for each range, the next position or the mark that the range is finished. A bookmark taken before a split still works after it: the children it does not name are read from their beginning, once their parents are finished. A subscription fetches the map again every 5 seconds to find new ranges.
One fencing token for the whole stream
A fenced producer on a scalable stream holds one token for the whole stream, kept on the stream's row beside the map. Fencing installs the token on that row first, then gives it to every open range, 8 at a time. Each range's leadership reads the token when it starts, so a range created later inherits it. If giving it to a range fails, the fence returns an error, and running it again finishes the job. The fence returns a bookmark: the end of every range at the moment the fence took effect.
Deleting and pruning
Deleting a scalable stream deletes every range, open and sealed, before the stream's own row. Sealed ranges also leave the map on their own. The retention job deletes a sealed range once all of its records are trimmed and none of its parents is still in the map. It also removes the range from the map. A trim that empties a range asks for that check at once. Only the retention settings of a scalable stream can be changed after it is created.
When a step fails
A crash can stop a split or a merge between any two steps. Each change first records an intent naming the ranges it will create, and the ids and tokens of those ranges come from the parent's id. A re-run therefore creates the same ranges and reaches the same map. A range that no map claims is deleted by the range-intent job after 5 minutes, unless one of its parents is still open and the change may still finish.
A range's leader fails like any stream's leader, and only the keys in that range wait for the failover. A one-shot append, or one part of an HTTP append, follows seals for up to 5 seconds before it reports an error. A producer session follows at most two seals for one append. The design of splits, merges, and readers is checked by two formal specifications, described in How Nova is tested.
Go deeper
Metadata keyspaces
Where the range map lives, and each range's own rows
Duties
The auditor's jobs, including the ones that split, merge, and prune
Isolating a noisy key
How a queue asks for a split at one key's hash
Back to the concepts: Scalable streams and Keys and ranges.