Architecture

The map of what exists — component planes, the interactions that matter, and the topologies you can run. Canonical diagrams live in ADR-012; this page mirrors them.

The system at a glance

flowchart LR
    subgraph clients[Clients]
        cli[firn-cli]
        grpc[gRPC clients]
        http[HTTP admin]
    end
    subgraph firnd[firnd - one process]
        httpapi[HTTP :9460]
        grpcapi[gRPC :9461]
        mesh[Mesh gRPC · mTLS]
        broker[broker]
        queue[queue]
        groups[groups]
        meta[meta]
        flog[FileLog]
        quorum[Raft]
        repl[replication]
        fed[federation]
        httpapi --> broker
        grpcapi --> broker
        grpcapi --> queue
        grpcapi --> groups
        mesh --> broker
        mesh --> quorum
        mesh --> fed
        broker --> meta
        broker --> flog
        queue --> flog
        groups --> flog
        repl --> quorum
        repl --> flog
    end
    cli --> httpapi
    cli --> grpcapi
    http --> httpapi
    grpc --> grpcapi
    flog --> disk[(local disk: segments + topics.json)]

Storage invariants (ADR-003)

  1. Offsets are assigned monotonically from 0 per partition — never reused.
  2. Fetch never returns records at offset ≥ the high watermark.
  3. After a crash, no torn tail record is ever visible: CRC-framed records are truncated on open.
  4. Committed group offsets advance monotonically (unless explicitly reset).
  5. Unacked queue messages are redelivered (at-least-once); DLQ after 3 attempts.

Flow 1 — produce (single node)

sequenceDiagram
    participant C as Client
    participant G as gRPC FirnService
    participant B as Broker
    participant L as FileLog
    participant D as disk
    C->>G: Produce(topic, key, value)
    G->>B: topic lookup + FNV partition
    B->>B: federation fence? (passive peer in scope → 409)
    B->>B: cluster lease advisor?
    B->>L: append frame (offset = HWM)
    L->>D: write + fsync
    L-->>B: offset
    G-->>C: ProduceResponse(partition, offset)

Flow 2 — queue claim & DLQ

sequenceDiagram
    participant C as Consumer
    participant Q as Queue engine
    participant A as __queue_attempts
    participant F as FileLog
    C->>Q: Pull(queue, max, visibility)
    Q->>A: increment attempts (max-fold at read)
    alt attempts greater than 3
        Q->>F: divert to the DLQ topic (queue plus .dlq suffix)
        Q-->>C: no delivery for this message
    else
        Q-->>C: deliveries (visibility lease held)
    end
    C->>Q: Ack(queue, delivery_id)
    Note over C,Q: lease expiry redelivers first. DLQ after 3 attempts

Flow 3 — cluster produce with a lease (followers catch up)

sequenceDiagram
    participant C as Client
    participant B as Any node (write path)
    participant ADV as Replication advisor
    participant Q as Quorum (Raft)
    participant F as FileLog
    C->>B: Produce(topic, ...)
    B->>ADV: WriteAllowed(topic, partition)?
    ADV->>Q: lease table lookup
    Q-->>ADV: yes/no
    alt this node holds the lease
        B->>F: append (HWM-ordered)
        B->>B: seal full segments → ReplicaPut to peers
        B->>Q: EntryBlockCommit
        B-->>C: offset
    else another node holds the lease
        B-->>C: FailedPrecondition (client routes via GetMetadata)
    end

Followers notice committed block descriptors and pull missing blocks via ReplicaFetch — content-addressed by SHA-256 of the raw frame bytes, so cross-node equality is checkable. Blocks flow user-topic and internal-topic alike.

Flow 4 — federation, passive (DR)

sequenceDiagram
    participant OP as Operator
    participant SINK as Sink
    participant SRC as Source
    OP->>SINK: POST federation peers (direction in, mode passive, topics list)
    Note over SINK: sink fenced — produce/pull/ack return 409 or FailedPrecondition
    SINK->>SRC: FederationFetch(topic, partition, first = cursor+1) over mTLS plus federation key
    SRC-->>SINK: CRC-checked frames (cursor+1 to HWM)
    SINK->>SINK: byte-identical apply, cursor upserted
    Note over SINK: clients read immediately. Writes rejected until cutover

Flow 5 — federation, active-active

sequenceDiagram
    participant A as Cluster A (writable)
    participant B as Cluster B (writable)
    A->>A: local produce at A-offsets
    B->>A: FederationFetch (A filters A-origin frames)
    A-->>B: only B-origin or unseen frames
    B->>B: AppendReoriginedFrames (fresh B-offsets, ts/key/value preserved)
    B->>A: symmetric pull, symmetric filter
    Note over A,B: both see all records. Global order undefined

Internal topics

TopicPurposeCompaction
__consumer_offsetsCommitOffset records (group·topic·partition → offset)upsert ≈ 1000 commits
__queue_attemptsclaim/DLQ attempt counters, max-foldfold at read; physical compaction (single node)
__auditevery admin mutation + authz refusal, all modesbudget rotation (operator, manual)
__api_keysSHA-256-hashed keys + roles + CIDR allowlistsmutation-appended, folded at open
__federation_peerspeer registry (addr, mode, direction, CA pin)low volume
__federation_cursorsimport progress + foreign-applied ranges (echo filter)upsert on import

In clusters, each is replicated byte-identically with a single write lease; non-holders fail closed (HTTP 503 / FailedPrecondition, holder in the message). They are never federated.

Deployment topologies

A

Standalone

Default. One binary, local disk, fsync durability, zero coordination. Dev, edge, single-worker pools. Single copy — disk loss = data loss.

B

3-node cluster (GA)

Single-region, fixed membership, embedded Raft, ≥2 byte-identical sealed-block copies, lease-fenced writes, GetMetadata routing. Full-restart upgrades only.

C

Active / passive DR (preview)

One-way byte-identical replication, sink fenced read-only, offsets preserved. Cutover runbook in repo. Perfect for east→west DR.

D

Active / active (preview)

Both clusters writable; records re-originated per cluster; A→B→A echo filtered server-side; no global order. Edge + cloud topologies.

Ports & listeners

ListenerDefaultContentsAuth
HTTP admin:9460/healthz, /metrics, admin API, /ui/Bearer (except /healthz)
Client gRPC:9461FirnServiceBearer + role
Mesh gRPC:9471Replica · Quorum · FederationmTLS (+ federation key on FederationService)

Diagrams render with Mermaid from the same source of truth as ADR-012. If JavaScript is disabled, the diagram sources are still readable as text.