krewe

Architecture

The router at the center of the network.

The orchestrator is the only privileged service in the krewe stack. It accepts inference requests, fans them out to three workers, evaluates consensus, and settles rewards on chain.

Five subsystems

Five subsystems in one process

WorkerManager — Holds every authenticated miner's WebSocket state. Runs heartbeats, computes peer scores, picks the replicas for any given job using a top-half-by-score + random-tail strategy that avoids winner-take-all dynamics.

JobRouter — Fans a single request out to REPLICA_COUNT workers, collects responses under a deadline, and surfaces the verdict to the original caller.

Consensus — Canonicalizes each output as sorted-key JSON, hashes it, and groups the responses. The largest group with size ≥ CONSENSUS_THRESHOLD wins; tiebreaks favor the first response received.

RewardLedger — In-process accumulator. Credits winners on every settled job. Supports snapshot/revert so a failed on-chain submission doesn't lose pending balances.

ChainClient — viem write client. Caches the on-chain batch nonce and submits batchDistributeRewardsevery settlement window.

What it can't do

Constraints by design

The orchestrator has only one privileged on-chain action: calling batchDistributeRewards with the credits accumulated in its ledger. It cannot mint $KREW, modify stake bounds, register workers, or pause the contract. The on-chain replay-nonce gate protects against accidental double-submission; the segregated reward pool means even a fully compromised orator wallet can't touch worker collateral.

Concurrency

Single process, single thread

Today the orchestrator runs as a single Node.js process. Worker state and the reward ledger live in memory. This is intentional for the MVP — it removes a whole class of distributed-systems bugs and keeps the latency floor low.

Multi-process HA is on the roadmap. The replay-nonce check on batchDistributeRewards already prevents two replicas from settling the same batch; what's left is sharing the worker registry and reward ledger across instances (Redis pub/sub is the likely path).