jonnify·bcs /bcs/trading

B8 · The Trading System — manuscript Part VIII

The capstone: every primitive in its role.

B1 gave every row a name, B2 gave the names a home, B3 put them in motion, B4 made reading them cheap. B8 assembles them into the worked project the whole series has pointed at — a trading platform on the as-built tree.

The design is the Operator's, written in docs/trading/; its status is PROPOSED, and it states its own law: "Nothing here is a record — the first rung's harness produces the first number this platform may ever claim." This chapter teaches that design, and quotes the committed floor it stands on — never a number the platform has not yet earned.

The Part VIII arc — four modules in reading order. Select a node to read its thesis.
8.1 engine 8.2 log + ledger 8.3 strategies 8.4 scale-out
readout · Select a module to read its thesis. Reading order runs left to right; B8.1 lands the engine — the Ring, the Book, and the Decider.
§1

The four modules

docs/trading/ · the design corpus
B8.1

The Engine — Ring, Book, Decider

The hot path: the Disruptor seat (EchoCache.Ring ingress, bounded publish/2, counted drops), the single-writer Book draining a pure Decider, and price-time priority falling out of the id law rather than a comparator.

3 divesbuilt
B8.2

The Log and the Ledger

The memory: one EchoCache.Journal per book under a pluggable Shadow, replay that equals live state, double-entry settlement in Postgres (one Ecto.Multi a posting), idempotent projections into Tables.

3 divesbuilt
B8.3

Strategies as Deciders

The layer above: a strategy is a Decider emitting intents, never orders; the four-stage pipeline; risk as gating deciders and the kill switch that is already a lane verb; the backtest is the live system replayed.

3 divessoon
B8.4

Fan-Out and the Scale-Out

Claims-only on the bus (29 bytes, never an object), placement by the audited hash32, CP matching and AP market data on partition, and the cross-shard saga over the log.

3 divessoon

A module card becomes a link when its pages ship; the dives per module are fixed in the chapter spec, and the reading order is the arc above. The platform is a PROPOSED design — its Exchange.* modules are taught as design, never as a measured result; the primitives they compose are committed records (the floor below).

§2

Three shapes, one wire

docs/trading/trading.md

A trading platform has four jobs that pull in different directions: sequence commands per instrument under a single writer; hold a latency budget in microseconds on the match path; stay durable and auditable — every fill a fold over facts; and fan out and follow up. The classic failure is answering all four with one primitive: a queue pressed into a log, a log into a bus, a bus carrying objects. The design rule is the opposite — three messaging shapes, each served by the primitive built for it.

ShapeCarriesServed by (as-built unless marked PROPOSED)
Commandone ordered command stream per instrument, one writerEchoCache.Ring ingress → Exchange.Book (PROPOSED) draining a pure Decider; sequence is branded mint order
Eventfacts emitted once, read by many, replayablethe claim-check bus (Appendix G) for fan-out; the Journal (B4.4) then per-instrument stream lanes for the log
Workretriable follow-ups: settlement, risk, reportingEchoMQ.Jobs / Lanes / Consumer — fair per-venue lanes (B3.4)
The master invariant. One instrument's book is mutated by exactly one process — the sole drainer of that instrument's Ring — and its state is reconstructable as a fold over an append-only event log. Sequence is mint order. Every primitive keeps its role: the queue is never a log, the log is never a fan-out bus, the bus never carries an object. Nothing on a hot path runs heavier than regular-scheduler work. Every id is branded and refused at the wrong door.
§3

The floor under the floor

committed records, quoted verbatim

The platform invents nothing under the hot path: it composes primitives this course has already taught from frozen records. The PROPOSED design earns its first number only when its own rung's harness runs — but the floor it stands on is committed today. The records B8 assembles:

content/echo_data/runtimes/elixir/ · the as-built floor B8 composesfrozen
bcs_rung_3_4_check.out   fair lanes (rotation + the kill switch)   PASS 8/8
bcs_rung_4_1_check.out   cache-aside (the read path)             PASS 6/6
bcs_rung_4_3_check.out   the single-writer ring (the ingress)    PASS 6/6
bcs_rung_4_4_check.out   the journal (append, replay)            PASS 6/6
bcs_hash_audit.out       the cross-runtime hash32 placement      PASS 4/4

The claim check (content/bcsG.md, Appendix G) and the connector referee (content/bcsH.md, Appendix H) are the two further committed records the bus and the wire stand on. The platform's own numbers — the match latency, the throughput, the fill counts — do not exist yet, and so they appear nowhere on these pages.

§4

Three milestones

docs/trading/trading.roadmap.md
A

The walking skeleton

TRD.1–TRD.5 — submit an order, watch it match in a Ring-fed single-writer book, replay the book from its Journal, read a position at hit speed, see the fill posted double-entry, watch settlement drain a fair lane. No unbuilt dependency.

milestone Adesign
B

The durable core

TRD.6 — replay any instrument from a per-instrument stream lane; attach a polyglot risk consumer through a consumer group. Gates on the connector's stream rungs (Appendix H, conn.1–conn.2).

milestone Bdesign
C

The scale-out

TRD.7–TRD.8 — place books across nodes by the audited hash, lose a node and watch a book hand off under the CP rule, flood a venue and watch the others hold.

milestone Cdesign

The full eight-rung ladder, with per-rung gates and recorded dependencies, lives in the trading corpus's roadmap. The course teaches the design module by module; each platform claim becomes a committed record at the rung that ships it, and none is claimed before.

§5

The parts it stands on

read the chapters under the capstone
§6

The doors

the sibling courses
§7

References

sources · related

Sources

Related