How reads find records

How reads find records

How Nova serves the newest records from the leader's memory and older records from object storage.

A read returns a stream's records from a position you choose. Any node can serve indexed records, those whose location the metadata store already holds. The newest records, which the metadata store does not list yet, come from the stream's leader, usually from its memory. A subscription on the leader wakes as soon as new records are acknowledged, without polling.

yes no yes no yes no yes no yes no Read at position P Below the trim watermark? Refused In this node's memory? Serve from memory Indexed? Storage, on any node This node leads? Serve from the leader's flights Lease held elsewhere? NOT_OWNER Recover, then serve
Where a read is served from. One response stays on one side of the indexed boundary, and the next request chooses again.

The parts

PartWhat it does
LeaderThe node that serves a stream's writes. Only it knows where the newest records are and when a reader has reached the end.
Tail window cacheThe leader's copy of recently acknowledged records in memory, 128 MiB by default, shared by both classes
RefA metadata row that says where a run of a stream's records is stored. A span ref points into WAL slots. A catalog row lists stream objects.
FooterThe index at the end of every stored object. A reader fetches it by byte range to find the chunks it needs.
Footer cacheA node's memory of the footers it has read, 256 MiB by default
Object cacheAn optional shared cache in front of the standard bucket
Read planA list of object byte ranges that a consumer fetches from storage itself

How a read finds its records

  1. The node checks the stream's trim watermark. A position below it is refused at once, even while the objects that held those records still exist.
  2. The node looks in its tail window cache. Cached records are already acknowledged and never change, so a hit needs no metadata lookup.
  3. For an indexed position, the node finds the covering ref with one lookup, then reads from object storage. Any node can do this.
  4. For a position past the indexed records, only the leader can serve. It finds the records in its own index of the flights it wrote. A node that does not lead the stream replies NOT_OWNER with the leader's address, and the client reconnects there. Nodes do not forward reads to each other.
  5. The response stops at the boundary between indexed and newer records, because each side comes from a different place. The next request repeats these steps from where it ended.

A response holds at most 8,192 records and 8 MiB by default, and a request can lower both. It always holds at least one record, even one larger than the byte limit. See API limits.

The newest records come from the leader

Nova acknowledges an append before the metadata store records where it is. For a short window, only the leader knows where the newest records are. The leader keeps each acknowledged flight's records in memory, without copying them, and finds a record by its sequence number. A reader near the end of the stream reads memory, with no metadata lookup and no storage request.

The cache keeps records after they are indexed, until it needs the space, and evicts the oldest first. So a reader that lags behind by less than the budget divided by the write rate still reads from memory. When a node takes 10 MiB/s of appends, the 128 MiB default holds about the last 13 seconds. On a miss, the leader reads the WAL slot by byte range. A flight larger than the whole cache is not cached, and the node logs it.

The backlog of acknowledged flights not yet indexed has a limit, and appends wait when it is full, so this window stays short. The cost of this design is that the leader serves both the writes and the newest reads of its streams. A node sends a reader to the leader instead of forwarding the read, so a read takes one hop at most.

Subscriptions wait for a wake

On the leader, a subscription that has read everything waits for a wake: a signal sent when an acknowledgement moves the end of the stream, or when the node stops leading it. The subscription takes the signal before it reads, and waits only when the read was empty. An acknowledgement that arrives between the read and the wait therefore still wakes it. A waiting subscription costs no metadata queries and no polling, and it delivers new records as soon as they are acknowledged.

On any other node, a subscription polls. It waits 5 ms after an empty read, doubles the wait up to 250 ms, and starts again from 5 ms after it delivers records. Each empty poll reads the stream's metadata. When it finds that another node leads the stream, the subscription ends with NOT_OWNER, and the SDK resumes on the leader from the same position.

Older records cost one lookup and a few byte ranges

For an indexed position, one lookup finds the ref that covers it. The reader then fetches the object's footer by byte range. The footer's index has fixed-width entries in sorted order, so the reader finds the right chunk without decoding the whole footer. It then fetches only the chunks it needs. While it sends one range, it already fetches footers and data for up to 8 more refs.

The footer cache keeps each decoded footer for up to 5 minutes and evicts the footer fetched longest ago first. A second read of the same object then costs only its data requests. For a record still in an Express transit bundle, the reader tries the bucket in its own availability zone first, then the others.

No read lists objects or fetches a whole object. The cost of a read grows with the records it returns, not with the size of the stream.

Read plans move history off the nodes

A read plan lists the objects and byte ranges that hold a run of a stream's records. A consumer fetches those ranges from object storage itself, so bulk history does not pass through a node. Any node can return a plan, with the same permission check as a read. A plan holds at most 256 entries. It says where it ends, and the consumer continues from there with a normal read or subscription, which also covers the newest records a plan never includes.

A plan expires after half the auditor's read grace, 5 minutes by default. The auditor waits the full grace before it deletes an object that no ref names, so every object in a valid plan still exists. A plan gives either short-lived signed URLs or the bucket and key, for consumers with their own storage credentials. Plans are available over gRPC only. The Gateway uses them by default for history and for subscription catch-up.

The object cache

Many nodes and the Gateway often read the same objects. An optional shared object cache, usually one per availability zone, sits in front of the standard bucket. A reader picks the cache instance for an object by hashing its key onto a ring that caps each instance's load. The cache is never the only copy. When an instance fails or is slow, the reader fetches the byte range from storage directly. The auditor sends its deletes through the cache, so a deleted object leaves the cache too.

When the leader fails

A stream that no node leads is vacant. Any node serves its indexed records. But if its last leader failed before indexing its newest flights, those acknowledged records are only in that node's WAL.

A read that needs the end of such a stream recovers them itself, once the failed node's metadata store session has expired. A tail check, a read that reaches the end, a fence, and a subscription waiting at the end all do this. They run ledger recovery, which fences the failed node's log and indexes what it holds, then serve. A producer opening the stream does the same, and the auditor does it for a stream nobody touches. Until the session expires, these reads still go to the failed node and fail, and the SDK retries them. Reads of older, indexed records work throughout. See Failure model.

A leader that hands a stream over on purpose first indexes everything it acknowledged, and keeps its lease until it has. Subscriptions keep waiting during that time, then move to the new leader.

Go deeper

Back to the concept: Reads.

On this page