Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Three Kinds of State

Every piece of data in a Mordecai application belongs to exactly one of three categories (spec §3). Getting this classification right is the most important design decision an app developer makes.

Ephemeral state

Exists only while the app runs: mouse positions, voice chat, live cursors, network sessions, temporary AI context. Never stored, never replicated, never on-chain. Plain in-memory application code.

Shared state

Persistent application data that should replicate between peers but needs no universal agreement: chat history, documents, game moves and replays, images, community content.

Shared state lives in Hypercore feeds:

  • Append-only — history can’t be rewritten.
  • Signed — every entry is authenticated by the feed owner’s key; a peer relaying your chess moves cannot forge them.
  • Replicated on demand — peers holding a feed serve it to peers who want it, directly over encrypted connections.

Shared state is authentic but not authoritative: you can prove who wrote what and in what order, but nothing forces every node in the world to store or agree on it. That’s exactly right for application data.

Economic state

Information every participant must agree on forever: wallet balances, contract storage, token ownership, escrow, the application registry.

Economic state lives on-chain, in a key-value store committed to by a Merkle root in every block header:

PrefixContents
a: + pubkeyaccount {balance, nonce}
cc: + contract iddeployed WASM code
cs: + contract id + keyper-contract isolated storage
app: + app idregistry entries (owner, pear key, version, bundle hash)

It changes only through signed transactions, executed identically by every validator, finalized by BFT quorum. It is intentionally small — consensus is the expensive tier.

Worked examples (spec §15)

AppOff-chain (feeds)On-chain
Chessboard state, moves, clocks, chat, spectatorstournament entry, wagers, escrow, payout
Redditposts, comments, votes, mod logscommunity ownership, mod permissions, treasury
Marketplaceproduct images, search, reviewslistings, ownership, escrow, settlement
AI serviceprompts, inference, conversationmicropayments, subscriptions, usage accounting

The pattern: scarce things on-chain, everything else off. Currency, ownership, escrow, identity, governance — on-chain. Content, computation, communication — off.

A fourth lane: group state

Shared state assumes one author per feed. Some app data is genuinely multi-writer — two players contending for the same tile, a guild world’s resources — but still only matters to the app’s own peers, not to everyone. That data belongs on an app chain: the same chain stack, instantiated per-app by its players, anchored back to L1 by quorum attestation. The classification question generalizes to who has to agree? — nobody (feed), the app’s peers (app chain), everyone (L1).