{
  "docVersion": 1,
  "id": "template-trading-order-book",
  "name": "Trading order book",
  "purpose": "Deterministic exchange core: ring-buffer ingestion, total-order sequencing, single-threaded matching, event-sourced journal, replayed by warm replicas.",
  "nodes": {
    "traders": {
      "type": "users",
      "label": "Trading Clients",
      "x": 20,
      "y": 240,
      "runtime": "FIX / binary gateways"
    },
    "gw": {
      "type": "gateway",
      "label": "Order Gateway",
      "x": 280,
      "y": 240,
      "runtime": "validate · rate-cap",
      "patterns": [
        "stateless",
        "replicated"
      ]
    },
    "rb": {
      "type": "queue",
      "label": "Ring Buffer",
      "x": 540,
      "y": 240,
      "runtime": "lock-free · bounded",
      "notes": "Bounded on purpose: when full, reject at the edge — backpressure beats an unbounded queue melting the engine."
    },
    "seq": {
      "type": "worker",
      "label": "Sequencer",
      "x": 800,
      "y": 240,
      "runtime": "stamps total order",
      "color": "purple",
      "notes": "The single point where 'simultaneous' becomes ordered. Everything downstream is deterministic because of this."
    },
    "me": {
      "type": "server",
      "label": "Matching Engine",
      "x": 1060,
      "y": 240,
      "runtime": "single-threaded state machine",
      "color": "green",
      "patterns": [
        "leader-elected"
      ],
      "notes": "No locks, no threads, no clock reads — consumes sequenced ops, emits events. Boring by design; determinism is the feature."
    },
    "journal": {
      "type": "ledger",
      "label": "Event Journal",
      "x": 1320,
      "y": 120,
      "runtime": "append-only",
      "patterns": [
        "replicated",
        "backup"
      ]
    },
    "replica": {
      "type": "server",
      "label": "Warm Replica",
      "x": 1320,
      "y": 380,
      "runtime": "replays → identical book",
      "style": "dashed",
      "patterns": [
        "standby"
      ]
    },
    "md": {
      "type": "bus",
      "label": "Market Data",
      "x": 1060,
      "y": 480,
      "runtime": "trades · quotes · depth"
    },
    "subs": {
      "type": "users",
      "label": "Subscribers",
      "x": 800,
      "y": 560,
      "runtime": "market data feeds"
    }
  },
  "edges": {
    "e1": {
      "from": "traders",
      "to": "gw",
      "fromSide": "right",
      "toSide": "left",
      "label": "new order / cancel",
      "animated": true,
      "flowSpeed": "fast",
      "patterns": [
        "rate-limit",
        "authenticated"
      ]
    },
    "e2": {
      "from": "gw",
      "to": "rb",
      "fromSide": "right",
      "toSide": "left",
      "animated": true,
      "flowSpeed": "fast",
      "patterns": [
        "backpressure"
      ]
    },
    "e3": {
      "from": "rb",
      "to": "seq",
      "fromSide": "right",
      "toSide": "left",
      "label": "drain"
    },
    "e4": {
      "from": "seq",
      "to": "me",
      "fromSide": "right",
      "toSide": "left",
      "label": "seq #184,224,001…",
      "animated": true,
      "flowSpeed": "fast",
      "patterns": [
        "ordered"
      ]
    },
    "e5": {
      "from": "me",
      "to": "journal",
      "fromSide": "right",
      "toSide": "left",
      "label": "append events"
    },
    "e6": {
      "from": "journal",
      "to": "replica",
      "fromSide": "bottom",
      "toSide": "top",
      "label": "replay",
      "style": "dashed"
    },
    "e7": {
      "from": "me",
      "to": "md",
      "fromSide": "bottom",
      "toSide": "top",
      "label": "publish",
      "style": "dashed"
    },
    "e8": {
      "from": "md",
      "to": "subs",
      "fromSide": "left",
      "toSide": "right",
      "label": "fanout",
      "style": "dashed",
      "patterns": [
        "compressed"
      ]
    }
  },
  "texts": {
    "t1": {
      "x": 20,
      "y": 430,
      "text": "why single-threaded wins here: the engine does no I/O\nand holds no locks — it just folds ordered events.\nDeterminism turns disaster recovery into `replay`.",
      "color": "green",
      "size": 12
    }
  },
  "meta": {
    "createdAt": "2026-07-13T09:00:00.000Z",
    "modifiedAt": "2026-07-13T09:00:00.000Z"
  }
}