Table of Contents

Orleans.Lattice.Api.Replication architecture

This page documents Orleans.Lattice.Api.Replication 10.5.0, in the documentation for Orleans.Lattice 10.5.0 (release line 10.5), built 2026-12-05. It is also published as markdown, with every table and list, at architecture.md, and llms.txt lists every page.

This facade is a thin, fail-closed control layer over the replication config authority. It owns three responsibilities and nothing else: resolve the tree name and authorize the caller, delegate to the engine, and scope discovery to the caller's grant. The package's separate, read-only peer-status facade is described in The peer-status read path.

The single narrowest seam

Every mutating operation authorizes at exactly one choke point before it touches engine state; the config read uses the same choke point as a per-tree filter (see Permission-scoped discovery). EnableReplicationAsync and DisableReplicationAsync first resolve the caller-supplied, tenant-local tree name to its effective id, then authorize that same id - the whole target tree - for the dedicated LatticeOperation.Replication capability through the shared ILatticeAccessGate; only on an allow do they call the engine authority. A deny throws LatticeAuthorizationDeniedException and the engine is never consulted, so a denied caller cannot author a single config dot.

Because a control operation acts on a whole tree, a partial (key-filtered) allow cannot narrow it and is treated as a deny. This mirrors the whole-tree enforcement the sibling backup facade uses.

Delegation to the engine authority

The facade holds no replication state. It delegates to ILatticeReplicationConfigAuthority in Orleans.Lattice.Replication, which authors the sys-replication-config tree:

  • Enable fixes the merge mode at enable time by writing an add to the enablement RwFlag and setting the MvRegister mode. Enabling an already-enabled tree under a different mode - or one whose mode is currently ambiguous - is rejected with LatticeReplicationModeChangeRejectedException; enabling under the same mode is idempotent, including when two regions enable the tree concurrently under the same mode - their enablements converge on that mode, not on an ambiguous one. A runtime precondition failure (for example a flag-based mode without a configured local replica) surfaces as LatticeReplicationPreconditionFailedException.
  • Enable with a bootstrap source composes the existing snapshot bootstrap: when bootstrapSourceClusterId is supplied, the authority requests a receiver-driven snapshot (through ILatticeReplicationAdmin.RequestSnapshotAsync) that pulls the named source cluster's pre-existing rows - which the change feed will not carry - into the local tree, then reports BootstrapRequested = true. It does so whether or not the local tree holds rows: a receiver drops, and acknowledges, every entry shipped before its own enrollment lands, so an empty receiver depends on the snapshot most (#5557). Enable the source cluster first, or the export refuses the unenrolled tree. The bootstrap cannot push the local rows to remote peers. An enable that finds the tree already enabled under the same mode - the usual case for a second region, because enrolment converges from the region that enabled first - still requests the named source's snapshot, unless a bootstrap from that source is already in flight on this receiver (#5594). A bootstrap that completed earlier is not taken as covering the source's rows, since it may have exported before rows this receiver dropped while not yet enrolled. The request takes the rate-limited routine re-seed path, so a repeat within LatticeReplicationOptions.OperatorReseedMinInterval (default 1 minute) of the last re-seed that silo honoured for the same tree and source cluster is not dispatched, and the result still reports BootstrapRequested = true.
  • Disable writes a disable-wins dot to the RwFlag and keeps the entry, with its last mode, in the config tree; it never purges peer data. Unless the static deployment map also declares the tree, its merge-mode resolution then returns no mode, but shipping does not pause: an already-active shipper keeps shipping the tree's new local writes, which a peer that has converged on the disable drops at its receiver-side enrollment gate. Disabling an absent or already-disabled tree is an idempotent no-op that authors nothing; disabling an enabled tree needs a configured local replica id to stamp the dot and otherwise fails with LatticeReplicationPreconditionFailedException. A later enable re-fixes the mode to the value it requests and, when bootstrapSourceClusterId is supplied for a tree that holds data, requests a fresh snapshot bootstrap; without it, no bootstrap runs.

Decommissioning a peer

DecommissionPeerAsync - the one operation of the separate ILatticeReplicationPeerAdmin facade, which AddLatticeReplicationApi serves from the same instance as ILatticeReplicationControl - is the one control operation that does not scope to a single tree, because a peer being decommissioned is a cluster-wide fact, not a per-tree one. It authorizes against the dedicated LatticeOperation.Replication capability over the cluster-wide scope rather than any single tree (the gRPC binding's transport authorizer sees the peer cluster id as the call's target; there is no MCP tool for it), before touching any engine state - an unauthorized caller is denied with LatticeAuthorizationDeniedException and nothing is read or written.

Once authorized, the facade:

  1. Refuses with LatticeReplicationPeerStillConfiguredException while peerClusterId is still present in ReplicationPeers. A configured peer's acknowledgement is still awaited through live topology regardless of what its durable enrollment says, so decommissioning it first would release nothing - the caller must detach the peer first. A detach alone never decommissions it: enrollment is untouched by a detach, which is exactly what lets the peer be re-attached without losing its place in a hold it was already pinning.
  2. Enumerates every registered tree - not only the currently replicated set - and removes the peer from that tree's durable cross-tree enrollment. Enrollment outlives a tree leaving the replicated set, so scoping to ReplicatedTrees would leave the peer pinning the decisions of a tree that was since un-replicated. The removal is idempotent and cheap for a tree the peer never enrolled on.
  3. For each tree whose enrollment actually contained the peer, also detaches that tree's shipper for the peer from the log synchronously, so a decommission that lands ahead of the shipper's own asynchronous detach cannot leave it attached and able to re-enroll the peer underneath the decommission.
  4. Handles the opposite direction - this cluster as the receiver of operations the peer originated - in two phases over every registered tree, so the outcome does not depend on the order trees are walked in (#4742). Both run unconditionally, independent of step 2's enrollment outcome, because enrollment governs this cluster shipping to the peer while these phases govern the peer shipping to this cluster.
    • Hold fenced imports. Before abandoning anything, it asks each tree's bootstrap coordinator to keep its read fence up if that tree's import from the peer still holds one. An abandon is not a decision: an abandoned barrier stops counting as undecided, so without this the import's next phase tick would lift its fence over a post-saga import whose sibling's staged prepare the next phase discards, serving the operation split. The fence stays up until the peer is re-added; the coordinator also re-reads the decommissioned-peer registry on every tick and fails closed.
    • Abandon the peer's barriers. It collects the cross-tree barriers recorded against every tree and abandons every undecided barrier whose origin is the peer. That durably withdraws the barrier from its trees' indexes and clears it to unopened, deciding nothing. A barrier is keyed by origin and operation, so every tree in its wait set is a replica of the peer: with the peer gone no tree is left to vote, and deciding on the arrivals so far would serve a verdict the operation's other trees never reach.
    • Discard the peer's pending buckets. For each tree, it settles every pending bucket the peer left, through the same stale-pending clearing a full bootstrap uses. A receiver stages a prepare on delivery, before its terminal, so a saga whose terminal never arrived - a cross-tree participant or a plain single-tree saga - would otherwise strand buckets that nothing ever consumes. Each saga is settled with the verdict its registry resolves, delegation included: an abandoned barrier's sub-sagas abort on every tree alike, a barrier that had already decided keeps its verdict on every tree, and a single-tree saga settles on its local decision.
  5. Marks the peer decommissioned in a durable, cluster-wide decommissioned-peer registry. The mark is written first, before steps 2 to 4, so every fenced import from the peer sees it from the start. From that point, cross-tree enrollment refuses to (re-)enrol that peer cluster id unless it is once again present in ReplicationPeers - so a decommissioned peer can only return through an explicit re-add (a fresh bootstrap), never through a shipper simply reconnecting. The replication driver clears that marker the moment a PeerChangeKind.Added topology event fires for the peer - ahead of any re-enrolment attempt, so the re-add is never itself refused by the marker it is meant to clear. Because the registry is a single cluster-wide record keyed by peer cluster id rather than per-silo state, this enforcement is already cluster-wide with no further propagation needed.

This is what resolves #4723 in full: without step 2, cross-tree enrollment only ever grows (shippers enrol, nothing un-enrols), so the origin-side cross-tree decision hold (#4684) would wait on a peer that is never coming back, forever; and without step 4, a receiver-side barrier for which the decommissioned peer was the origin would wait forever too, because nothing else ever tells it that peer is gone for good. The transaction registry's own purge pass re-asks the origin-side hold at most every TxDecisionRetention / 2 (capped at 30 seconds) for expired tombstones, so that release is not immediate - it is bounded by that cadence, not by this call returning; the receiver-side abandonment in step 4, by contrast, is synchronous with this call. A later re-add of the same peer cluster id is a fresh bootstrap: the shipper's own detach clears its log registration, so re-attaching enrols the peer again rather than resuming stale enrollment; step 5's registry clear lets that enrolment actually land instead of being silently refused, and before clearing it the re-add also abandons every barrier the peer still has on this receiver - one a terminal already past the enrolment gate reopened after step 4, a decided one, or a tombstone - so none holds a tree's import fence against the fresh bootstrap, and after clearing it re-drives every import whose fence the decommission held from a fresh export, so the fresh drain decides whether that fence lifts; and the stale-pending clearing of #4701 runs on that bootstrap as it does on any other.

The result, ReplicationDecommissionPeerResult, reports TreeCount - the number of registered trees the decommission visited, including trees the peer was never enrolled on - and AlreadyDecommissioned, true when an earlier call had already marked the peer decommissioned. The full fan-out runs either way, so a repeated call is idempotent.

Permission-scoped discovery

GetReplicationConfigAsync reads the authority's per-tree status set, then filters it: a tree is included only if the caller passes the same fail-closed authorization the mutating operations use. A per-tree denial is swallowed - the tree is silently omitted - so the report never reveals a tree the caller may not manage, and never throws on a partial grant.

Fail-closed ambiguity

The merge mode is stored in an MvRegister, so two clusters that concurrently enable the same tree under different modes both survive convergence. When the compiled snapshot sees more than one distinct live mode for a tree it marks the tree ambiguous and the resolver returns no mode rather than picking one. Shipping does not pause, though: an already-active shipper keeps shipping the tree's new local writes, which a converged peer - resolving no mode for the tree either - drops at its receiver-side enrollment gate. The facade surfaces this as ReplicationTreeConfigEntry.Ambiguous = true with a null Mode. The engine-side detail is documented in runtime replication configuration.

Ordering guard

AddLatticeReplicationApi() checks at registration that ILatticeReplicationConfigAuthority has been registered and throws with an actionable message if it has not, so a host that forgot enableRuntimeConfig: true on AddLatticeReplication(...) fails fast rather than at first call.

The peer-status read path

ILatticeReplicationStatus is a separate, read-only facade with its own registration, AddLatticeReplicationStatusApi(). It reads the replication engine's per-link telemetry rather than the config authority, so it needs AddLatticeReplication(...) registered first - it checks this at registration and throws InvalidOperationException otherwise - but neither enableRuntimeConfig: true nor AddLatticeReplicationApi().

  • Where the numbers come from. Each silo keeps the per-link counters of the shippers and appliers it hosts in memory. Each read fans out to every active silo through a per-silo grain service, each silo answers with a bounded number of rows after the cursor, and the answers are merged. When more than one silo reports the same link - a shipper rebalanced to another silo leaves a stale copy behind, and an inbound link exists on every silo that applied a batch from that peer - the copy with the most recent successful contact is kept whole, so its backlog, error streak, and in-flight count are never mixed across silos; when no copy has made contact, the one with the longest error streak, then the larger backlog, is kept. A silo that fails to answer fails the whole read, because a partial answer would present that silo's links as absent rather than unknown. The read path holds no state, schedules nothing, and never touches the ship or apply path.
  • Tenant and authorization. Every call confirms that the caller's tenant resolves and fails closed with LatticeTenantAccessDeniedException otherwise. A tree filter is resolved to its effective, tenant-scoped id and authorized for LatticeOperation.Replication over the whole tree before any telemetry is read; a denied filter returns an empty page. Without a filter, each tree's verdict is computed once per call and the rows of a tree the caller may not manage are skipped, so the report never reveals that tree.
  • Paging. Rows are ordered by effective tree id, then peer region id, then direction. Each read asks for up to one row more than the page size, so a full page learns whether anything follows without another round trip, and rows the caller may not see are skipped by reading further rather than by ending the page early. The continuation token is opaque and versioned and encodes only the key of the last row the caller was shown. It is treated as a position to validate, never as authority: every row after it is authorized again. A malformed token, a token longer than 4,096 characters, or a token of an earlier format version is rejected with ArgumentException.
  • Health. Each row's ReplicationLinkHealth is derived from that row alone against the LatticeReplicationStatusOptions thresholds, without reading a clock: the time since last contact is measured when the row is read. See Configuration.

See also