Mirexa

Wiki Cluster

Cluster architecture

How a Mirexa cluster is put together — a Raft control plane that decides where data lives, and a data plane that never passes through it.

A Mirexa cluster is a set of identical mirexa-server processes that share one keyspace of streams. It is built from two planes that are kept strictly apart: a small control plane, replicated by Raft, that decides which node serves what, and a data plane that stores and serves candles and ticks and never routes a single record through consensus. This page is the map; every other page in this section zooms into one part of it.

Clustering is off by default (cluster.enabled: false). A node with it off behaves exactly as a single-node Mirexa does, and nothing on this page applies to it.

The two planes

Control plane Data plane
What it holds The node registry, the partition directory, the cluster settings, in-flight migration intents, revoked issuer keys Candles, ticks, chunks, indexes, gap records, stream metadata
How it is replicated Raft (hashicorp/raft), one consensus group for the whole cluster Primary → copy, asynchronously, outside Raft (pull replication over gRPC)
Who writes it The Raft leader applies every change; any node may propose The partition's primary; copies only install what they pull
Listener gRPC control listener (control.addr), plus the Raft transport (cluster.raft_addr) Wire-protocol listener (network.addr), plus the replication listener (cluster.replication_addr, mutual TLS)
Cost per event One log entry per decision (a registration, a placement, a fence) None from consensus; a write is acknowledged after the primary's own WAL fsync

Candle and tick data never enters the Raft log. Consensus is priced for decisions, not a firehose: a quorum round per ingest batch would add a network round trip and a second fsync to every write, and would store every record twice (once in the Raft log, once in Mirexa's own WAL and chunks). What Raft decides about the data path is only which node is a partition's primary, and at which epoch.[1] A stream's existence is not replicated either: a stream lives on its partition's primary, and the partition is computed from the stream's name, so a catalogue of stream names would be a second source of truth.

The control plane's replicated state is one object, cluster.State, applied by the Raft state machine in internal/raft. It holds:

  • The node registry — every node's id, its Raft, data, control and replication addresses, its lifecycle status (ONLINE, LEAVING, OFFLINE, OFFLINE_LEAVING, DECOMMISSIONED) and its incarnation (the log index of the registration that created the record).
  • The partition directory — for each partition: one primary, its secondary copies, the in-sync subset, the fencing epoch, and any divergent copies a failover set aside.
  • The cluster settings — partition count, compression codec, liveness timeout, replication factor, and a version for compare-and-set updates.
  • Migration intents — partitions an operator, the rebalancer or a drain has asked to move.
  • Revoked issuer keys — token-signing keys the cluster no longer trusts.

See The control plane for how it is replicated and changed.

Every node is the same binary

There is no controller role and no separate coordinator process. Every node runs the same binary, carries the same seed list, and holds a full copy of the control-plane state, because every node is a member of the Raft group: a few are voters (3 by default, cluster.voters), the rest are non-voters that receive and apply the log but do not count toward a quorum.[2] That is what makes routing cheap: a node resolves "who serves this partition" with a map lookup against state it already holds, with no network round trip and no consensus entry.[3]

A new node is always admitted as a non-voter; the leader promotes caught-up non-voters until the group reaches its voter target, and never moves it to an even count. Three voters can lead a cluster of any size — the voter count bounds how many control-plane failures the cluster survives, not how many data nodes it has. See Joining, draining and decommissioning nodes.

Partitions, primaries and copies

The keyspace is divided into a fixed number of partitions (partition.count, default 4096, a power of two, immutable once the cluster agrees on it). A stream's partition is a hash of its symbol and exchange, so every timeframe of one instrument lands in the same partition. See Partitions and routing.

Each partition has exactly one primary — the only node that accepts writes for it — and zero or more copies (secondaries) on other nodes. There is no per-partition quorum, term or election: a partition is not a Raft group. Copies are replicated from the primary asynchronously and are byte-identical to it by construction, because a copy installs the primary's own chunk files and index entries rather than re-encoding anything.[4]

How many copies each partition should have is the cluster's replication factor (cluster.replication_factor, default 1 meaning no copies, range 1–7). A leader-local loop adds missing copies; it never removes one. See Replication.

Each copy is in one of two states, derived from the directory and never stored:

State Meaning
SYNCING Named a copy, still seeding or catching up. Not a failover candidate; serves no reads.
IN_SYNC Has been level with the primary's durable position recently (within two liveness timeouts plus two seconds). A failover candidate, and may answer reads.

A write is acknowledged once the primary has made it durable in its own write-ahead log. It does not wait for any copy. A primary that crashes can therefore lose writes it acknowledged after its copies' last pull — measured at milliseconds' worth in practice and bounded by design. See Replication.

Pull replication

The copy dials the primary and asks; the primary keeps no per-follower state. Two server-streaming RPCs on the replication listener do the work:

  • Seed bulk-transfers a partition's flushed state — stream metadata, chunk files, index entries, gap records, tick chunks — skipping whatever the copy already holds.
  • Tail streams the primary's write-ahead-log records for the partition as they land, with a heartbeat every second carrying the primary's durable position.

A copy writes tail records verbatim into a per-partition replica log and does not ingest them: chunks only ever come from the primary, through seed rounds. When the copy becomes primary, that replica log is replayed the way a crash's WAL is replayed. The cursor lives with the copy, so a restart on either side loses nothing it needs.[5]

How a request flows

flowchart LR
  C[Client] -->|write / read| A[Any node]
  A -->|REDIRECT partition, epoch, address| C
  C -->|write + epoch| P[Primary of P]
  P -->|WAL fsync, ack| C
  S[Copy of P] -->|Seed / Tail over mTLS| P
  subgraph Control plane
    L[Raft leader] --- V1[Voter]
    L --- V2[Voter]
    L -.log.-> N[Non-voters]
  end
  P -.heartbeat, lease.-> L
  S -.heartbeat, in-sync proposals.-> L
  1. A client sends a request to any node. That node resolves the stream's partition against its own applied directory. If another node is primary, it answers with a REDIRECT naming the partition, the epoch and the primary's data address — before anything is dispatched, so following it is a first attempt, never a retry.
  2. The client sends the write to the primary, carrying the epoch it was told. The primary checks the epoch, checks it still holds a current lease, writes the WAL, fsyncs and acknowledges.
  3. Copies pull the new records over Tail and the flushed chunks over periodic Seed rounds.
  4. Every node heartbeats the control-plane leader. The heartbeat keeps it from being fenced and renews its primary lease; a node whose heartbeats stop is fenced, and after a further liveness timeout its partitions fail over to an in-sync copy.

What the control plane does on its own

Eight loops run on every node and act only on the current leader:

Loop What it does On by default
Fence Marks a node silent past the liveness timeout OFFLINE Yes
Failover Moves a fenced primary's partitions to in-sync copies, one liveness timeout after the fence Yes
Placement Gives every unassigned partition a primary Yes
Migration Advances recorded migration intents step by step Yes
Rebalance Plans byte- and write-rate balance; executes only with cluster.rebalance_auto Plans yes, executes no
Promotion Grows the voter set; removes decommissioned voters Yes
Drain Moves a draining node's primaries, then its copies; decommissions it when empty Yes
Replication Adds copies to partitions below the replication factor Yes (a no-op at factor 1)

See The control plane.

What is deliberately not here

  • No request forwarding. A node that does not serve a stream redirects; it never proxies, because a proxying node would hold a write it does not own and could no longer promise it stored nothing.
  • No autonomous mode. A primary that cannot be vouched for by the control plane stops serving within its lease. The data path does not depend on consensus being up for its own operation, but serving as a primary requires the control plane's acknowledgement.
  • No synchronous replication. Acknowledgements never wait on copies.
  • No zone or rack awareness. Node records carry no topology.

References

Source

Tests

Further reading

External

  • Diego Ongaro and John Ousterhout, "In Search of an Understandable Consensus Algorithm (Extended Version)", USENIX ATC 2014 — https://raft.github.io/raft.pdf
  • HashiCorp, hashicorp/raft — https://github.com/hashicorp/raft
  • Apache Kafka documentation, "Replication" (leader/follower pull, in-sync replicas) — https://kafka.apache.org/documentation/#replication
  • KIP-500, "Replace ZooKeeper with a Self-Managed Metadata Quorum" (a small controller quorum over many brokers) — https://cwiki.apache.org/confluence/display/KAFKA/KIP-500%3A+Replace+ZooKeeper+with+a+Self-Managed+Metadata+Quorum

  1. internal/cluster/state.go package comment; cluster.Assignment in internal/cluster/partition.go. ↩︎

  2. ClusterConfig.Voters in internal/config/config.go; the promotion rule in internal/control/promotion.go. ↩︎

  3. partitionResolver.ResolveStream in cmd/server/resolver.go reads raft.Node.LocalLookup, a non-linearizable local read. ↩︎

  4. The replication schema's header in proto/mirexa/replication/v1/replication.proto: payloads are the engine's own encodings inside bytes fields. ↩︎

  5. "Pull, not push" in proto/mirexa/replication/v1/replication.proto; replicaTailApply in cmd/server/replica.go. ↩︎