Wiki Cluster
Reads from copies
When a Mirexa copy answers a read instead of the primary — replica reads by default, the staleness bound, stickiness and read-your-writes, and stale reads while a primary is down.
A partition's in-sync copies hold almost everything its primary holds, so they can answer reads. Mirexa uses that in two ways. Replica reads spread ordinary candle reads over a stream's primary and its copies — on by default in the routing client, with a server-side bound on how far behind a copy may be. Stale reads let a read that explicitly allows a stale answer be served by a copy when the primary cannot answer at all, such as a dead primary not yet failed over. Either way the answer is marked stale and says how current it is. Writes always go to the primary.
What a copy can answer
A node answers a read from its copy only if all of the following hold at that moment:[1]
- The request allows a stale answer (
AllowStaleon the query, or per sub-query in aQUERY_MULTI). The routing client sets it for you under the replica-read policy. - The node is running a catch-up for the partition and the directory lists it in sync.
- The copy has been level with its primary at least once since its catch-up started, and its
last level instant — the last primary heartbeat it covered — is no older than
cluster.copy_read_max_staleness(default 5 s; 0 removes this bound, leaving only the in-sync set's own2 × liveness_timeout + 2 s). - The node holds a current lease: a node the control plane cannot vouch for may not have applied a revoked key or anything else decided since it was cut off, so it answers nothing.
If any condition fails, the node answers with an ordinary redirect to the primary, exactly as a node that holds no copy would. The copy answers from its seeded chunks with the replica log it is still holding — the records not yet flushed into a seeded chunk — merged under them in memory.
The answer carries Stale and LevelAt — when the copy was last level with its primary. That is a
lower bound on how far behind the answer may be, not an estimate of how many candles it lacks.
Never served by a copy: writes, tick queries, and rollup (query-time bar) queries — the
codec refuses AllowStale on the last two.
Keep
copy_read_max_stalenessabove one second. A copy is level as of the last 1 s tail heartbeat it covered, so even a healthy copy's level age reaches nearly a second between heartbeats (0.996 s worst case measured over two seconds of sampling, 2026-10-23, one laptop). A smaller bound refuses copies that are keeping up.
Replica reads by default
The routing client (wireclient.RoutingClient) sends a candle query to one member of
{primary, in-sync copies} of its partition, unless told not to:[2]
- Finding copies. The client holds no directory. It reads
LIST_NODES, which says how many partitions each node is a copy of, and never asks a node holding none (the list is reused for 5 s). Whether a node holds this partition's copy is found by asking: a node that does not, or whose copy is refusing, redirects, and the client remembers that per node and partition for 5 s (30 s for a node it could not reach). - Sticky. A stream is mapped to one member by a hash seeded per client, so successive reads of a stream come from the same node and its newest bar never moves backwards between two nodes. Load still spreads across streams and across clients.
- Read your own writes. A stream this client wrote — or is writing, or failed to write — within
ResilienceOptions.ReadAfterWrite(default 10 s; negative turns it off) is read from its primary. Reconciling an ambiguous write means reading it back, and a lagging copy would say it is missing. Writes by other processes are not tracked; such a reader sees a copy's lag, which the server bounds. - Never fails a read. Anything a replica attempt does not answer with data — a redirect, a refused connection, a non-OK status — is asked again of the primary through the ordinary routing path. The policy can add one round trip to a read; it cannot fail one.
- Fan-out. In
QueryMultiAll, each sub-query is drawn the same way, and a copy's share of a batch goes to it in one leg.
Opting out
| Scope | How |
|---|---|
| Whole client | ResilienceOptions. |
| One call (and every query under its context) | wireclient. |
WithFreshReads wins even over a request that sets AllowStale itself. A PrimaryReads client
still honours an explicit AllowStale on a request.
Clients that do not run the policy: the Python SDK routes but always reads from the primary (it
does not implement replica reads), and the public Go client package does not route at all.
mirexa-cli load and the web dashboard use the routing client and therefore read from copies by
default; the dashboard's gap fills are pinned to the primary by the read-your-writes rule.
What a reader can rely on
Tested on real nodes: for a stream the primary only appends to, every answer from either node is a gap-free prefix of what the primary ends up holding — no hole, no candle it lacks, no different value — and one client's successive answers never shrink, across a replication link cut mid-run and a staleness bound running out. A correction is read as either the old or the restated value, never a third.
What it buys
Measured 2026-10-23 on one laptop with both server processes and 16 readers sharing its cores
(TestServerBinary_ReplicaReadThroughputIsMeasured, three runs): replica reads 93K, 101K and 98K
reads/s against 65K, 96K and 101K primary-only — inside the noise. Spreading reads is expected to
pay when a copy has hardware of its own; that has not been measured. The routing decision itself
costs about 262 ns and one allocation per read.
Stale reads when the primary is down
A read that allows a stale answer — explicitly, or under the replica-read policy — and that fails as
routed (the primary is unreachable, or refused with PartitionUnavailable because it is fenced)
falls back: the routing client asks each node LIST_NODES names in turn until one answers, and an
in-sync copy answers.[3] This is the case it exists for: a primary that has died but has not
been failed over yet, which takes about two liveness timeouts.
- In
QueryMultiAll, a dead node's sub-queries that allow a stale answer are re-asked of the serving nodes; the others come back unanswered with a*PartialResultError. - A read that opted out (
WithFreshReads, aPrimaryReadsclient withoutAllowStale, or a stream this client just wrote) fails where it stands.
Give clients more than one contact point. A routing client whose only contact point is the dead primary cannot ask anyone where anything else is.
Subscriptions on copies
A live subscription can also be served by an in-sync copy: a primary under load may offload a new
subscriber that allows it to one of its copies, and each delivered frame carries the copy's
LevelAt. A subscription already being served from a copy is not cut if the copy later falls past
the staleness bound — the bound is checked when the stream is resolved. See
Subscribing to live data.
Observability
| Signal | Where |
|---|---|
mirexa_ |
Server: reads this node's copies answered (each QUERY_ sub-query counts) |
RoutingClientStats. — Answered, Refused, Pinned |
Client: whether reads are being spread or are falling back |
RoutingClientStats. — Fallbacks, Answered, Legs |
Client: stale-read fallback after a primary failed |
mirexa_ |
Server: how long ago this node's furthest-behind copy was level |
References
Source
- Replica-read policy,
WithFreshReads, stale fallback,ResilienceOptions partitionResolver.copyReadnetwork.CopyRead, multi-query copy answersQueryPayload.AllowStaleClusterConfig.CopyReadMaxStaleness
Tests
TestStaleRead_ACopyAnswersWhileItsPrimaryIsDown,TestStaleRead_ACopyOutsideTheInSyncSetRedirects,TestStaleRead_ACopyBeyondItsStalenessBoundRedirects,TestStaleRead_ACopyWithoutALeaseAnswersNothing— /cmd/server/stale_read_test.goTestReplicaReads_AStreamIsStickyToOneNode,TestReplicaReads_AStreamJustWrittenIsReadFromThePrimary,TestReplicaReads_AStreamBeingWrittenIsAlreadyPinned,TestReplicaReads_AnOptOutNeverReachesTheCopy,TestReplicaReads_FreshReadsWinOverAnExplicitAllowStale,TestReplicaReads_TicksAndRollupsStayOnThePrimary,TestReplicaReads_ADeadCopyNeverFailsARead,TestReplicaReads_APlainReadSurvivesADownPrimaryOnACopy— /internal/wireclient/replicas_test.goTestReplicaReads_EveryAnswerIsAPrefixOfThePrimarysDataThroughACutAndABound,TestReplicaReads_ADeadPrimaryCostsPolicyClientsNothingAndOptedOutClientsTheirReads,TestReplicaReads_ACorrectionIsSeenAsOldOrNewNeverAMixOfOthers,TestReplicaReads_ManyClientsManyReadsNoAnswerIsEverWrong— /cmd/server/replica_read_invariants_test.goTestServerBinary_ClientsSpreadTheirReadsOverAPrimaryAndItsCopy,TestServerBinary_ACopyHonoursItsConfiguredStalenessBound,TestServerBinary_ReplicaReadThroughputIsMeasured— /tests/server_binary_replica_reads_test.goTestStaleFallback_GoesPastNodesThatCannotAnswer,TestStaleFallback_AFanOutRetriesADeadNodesStaleSubQueriesOnACopy— /tests/stale_fallback_e2e_test.go
Further reading
External
- Douglas B. Terry et al., "Session Guarantees for Weakly Consistent Replicated Data", PDIS 1994 (read-your-writes, monotonic reads) — https://www.cs.cornell.edu/courses/cs734/2000FA/cached%20papers/SessionGuaranteesPDIS_1.html
- Apache Kafka, KIP-392, "Allow consumers to fetch from closest replica" — https://cwiki.apache.org/confluence/display/KAFKA/KIP-392%3A+Allow+consumers+to+fetch+from+closest+replica