Leadership and failover
How Nova gives each stream one leader, moves it between nodes, and replaces it when a node fails.
Each stream has at most one leader, the node that accepts its writes. One writer per stream gives every record a sequence number with no gaps and no coordination between nodes. Any node can become a stream's leader. Nova places leaders where there is spare capacity, moves them to balance load, and replaces a failed leader within seconds, without copying any data.
The parts
| Part | What it does |
|---|---|
| Leadership | The state a node keeps while it leads a stream: the next sequence number, the open producers, an idle timer, and the lease |
| Lease | A metadata record that names the leader. It lasts as long as the leader's metadata store session. |
| Session | A node's connection to the metadata store. It expires 10 seconds after the node stops renewing it with an external store, and 15 seconds with the built-in one. |
| Epoch | The number of one of a node's ledgers. Fencing a ledger stops any writer still using it. |
| Handoff | A planned move of a stream's leadership from one node to another |
| Rebalancer | A loop on every node that moves leaderships off busy nodes |
How a stream gets a leader
- A producer opens a stream that no node leads. The node it reaches chooses a leader from the live nodes, as described in Choosing a leader.
- If it chose another node, it replies
NOT_OWNERwith that node's address. The client reconnects there and remembers the leader. - The chosen node writes the lease into the metadata store. The write succeeds only if no other node holds the lease.
- Before it accepts a write, the new leader makes sure every record the previous leader acknowledged is indexed. After a clean handoff, a mark left by the previous leader proves this at once. Otherwise the node runs ledger recovery on the previous leader's log.
- The leader numbers new records from the end of the stream. Other producers of the same stream join the same leadership.
Leases and fencing
Nova uses two separate mechanisms for one leader. The lease tells every node who leads a stream, so writes and recent reads reach one place. It expires with its holder's metadata store session. A lease can briefly outlive the leadership behind it, for example while a departing node finishes, or after a node lost the reply to its lease request.
A lease alone cannot stop a node that only seems dead. A node that paused, or lost its network, may still try to write after its lease expired. Storage fencing stops it. Before a successor recovers a node's ledger, it fences it: it writes a marker into the first empty slot, so no later write in that ledger can ever be acknowledged. The old node finds the marker on its next write and stops.
The lease says which node should write, and the fence stops any other node from committing. Epochs number a node's ledgers in one class, not a stream's leaders, so one fence covers every stream the node led. See Epochs and fencing.
Choosing a leader
Nova ranks the live nodes for each stream by rendezvous hashing and takes the top two. The first wins, unless the second carries less load by both 20% of the pair's mean and 1 MiB/s. Load here is the bytes per second of appends and recent reads a node serves. Within that margin, the hash decides, so many streams opened at once spread across the fleet instead of all choosing the least loaded node.
This is the "power of two choices" method. Comparing two candidates spreads load well without checking every node, and the ranking stays stable as nodes come and go. Draining and saturated nodes are not candidates. When no node is eligible, the open fails with an at-capacity refusal, ResourceExhausted. Placement only chooses where a new leadership starts. It never moves an existing one.
Idle timeout and vacancy
On a stream whose producer policy is any, a leadership stays for 30 seconds after its last producer closes. A producer that opens in that time reuses it, with no lease change and no recovery. After the timeout the stream becomes vacant. On a fenced stream, the leader releases at once when the last producer closes, so the next fenced producer can take over without waiting. The admin UI labels a vacant stream "Idle". That label means no node leads it. It is a different state from the 30-second idle period above.
A vacant stream holds no memory on any node, and any node can still read its indexed records.
Handing a stream over
A handoff moves a stream's leadership on purpose: for a drain, a rebalance, or a shutdown. It moves no record data, because every acknowledged record is already in object storage.
The departing leader waits for its in-flight batches. It then writes refs for every acknowledged record that is not indexed yet. This release flush writes metadata only. Last, it writes a clean-release mark and releases the lease. The successor finds the mark when it opens the stream, and knows that nothing is left to recover.
If the departing leader cannot finish, for example because the metadata store is slow, it keeps the lease and tries again. Opens meanwhile get a retryable refusal. A producer that reaches the old leader during the handoff is held for up to 2 seconds, or half its remaining deadline if that is shorter, until the lease is released. Its redirect then leads to a node that can take the stream.
Rebalancing
Every 5 seconds, each node checks its load. Three rules can start a handoff:
| Rule | Starts when | What it moves |
|---|---|---|
| Saturation relief | The node is saturated | One stream per check: the hottest of its 8 busiest streams that a less loaded node can take |
| Spreading | The node is above half its capacity, but not saturated | About every 30 seconds, one stream whose placement now prefers a less busy node |
| Imbalance correction | For 3 checks in a row, the node is over 20% above the fleet mean in load or in streams led, and over 1 MiB/s or 500 streams above it | Half the excess, toward nodes below the mean, at most 200 streams per pass |
Saturation relief moves a stream only if the target's load, plus twice the stream's load, stays below the source's. Otherwise the stream would bounce straight back.
A node is saturated when its busiest resource passes 85% of capacity, and it stays saturated until that falls below 70%. The gap stops a node from flipping between the two states. Nova measures four resources that a handoff can relieve: CPU time, network bytes (appends in and recent reads out), retained memory, and the age of the oldest flight not yet indexed. An age of 2 minutes counts as full. Network and memory count only when the node knows its capacity for them. A saturated node gets no new leaders and hands streams to other nodes. The settings for each resource are on Sizing.
When no other node can take any of its streams, the node reports itself stranded. If its hottest stream is a range of a scalable stream, it asks for that range to be split, which spreads the keys over more leaders. A plain stream that alone exceeds one node's capacity cannot be helped by moving it. Use a scalable stream, or add larger nodes.
Refusing new work at a limit is a different thing, called shedding. See Backpressure.
When a leader fails
A node that stops cleanly hands its streams over first. A node that crashes cannot. Its leases stay until its metadata store session expires, 10 seconds after its last renewal with an external store and 15 seconds with the built-in one. Writes to its streams fail meanwhile, and the SDK retries them.
Once the session expires, the next producer to open one of its streams gets a new leader, which recovers the failed node's ledger before it serves. Reads that need the end of the stream run the same recovery without waiting for a producer. No acknowledged record is lost, and sequence numbers continue without a gap. See Failure model for the timings.
Go deeper
Leadership and leases
The fleet records, safe departure, and orphaned leases
Epochs and fencing
How a ledger is fenced, and why every fencer finds the same cut
Ledger recovery
How a successor indexes a stopped ledger
Back to the concepts: Writer coordination.