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 four modules
docs/trading/ · the design corpusThe 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.
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.
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.
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.
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).
Three shapes, one wire
docs/trading/trading.mdA 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.
| Shape | Carries | Served by (as-built unless marked PROPOSED) |
|---|---|---|
| Command | one ordered command stream per instrument, one writer | EchoCache.Ring ingress → Exchange.Book (PROPOSED) draining a pure Decider; sequence is branded mint order |
| Event | facts emitted once, read by many, replayable | the claim-check bus (Appendix G) for fan-out; the Journal (B4.4) then per-instrument stream lanes for the log |
| Work | retriable follow-ups: settlement, risk, reporting | EchoMQ.Jobs / Lanes / Consumer — fair per-venue lanes (B3.4) |
The floor under the floor
committed records, quoted verbatimThe 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:
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.
Three milestones
docs/trading/trading.roadmap.mdThe 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.
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).
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.
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.
The parts it stands on
read the chapters under the capstoneEchoCache
Part IV — the ring the engine admits through and the tables it reads: cache-aside, the single-writer ring, coherence by mint time, the journal that replays.
B3The Bus — EchoMQ, Valkey-native
Part III — the work lanes (settlement, risk) and the log: jobs as entities, the state machine, fair lanes, the connector.
B2The Elixir BCS Core
Part II — the stores and the canon: a system as an OTP application, property stores, the CHAMP forest, archetypes, relations.
The doors
the sibling coursesEchoMQ — the protocol, in depth
The bus the work lanes and the log ride, taught rung by rung: the keyspace, the Lua inventory, conformance.
/redis-patternsRedis Patterns Applied
The substrate under the engine: the bounded ring, sorted sets, atomic Lua, the single-writer move.
/elixirFunctional Programming in Elixir
The umbrella, and the functional core the Decider and the strategies are written in.
References
sources · relatedSources
- Fowler — The LMAX Architecturethe Business Logic Processor and the single-writer case the engine takes onto the BEAM
- The LMAX Disruptor (technical paper)the bounded ring, sequences, batching — the Disruptor seat the Ring fills
- Chassaing — Functional Event Sourcing Deciderdecide / evolve / initial state — the pure core of the book and of every strategy
Related
- BCS — the course homethe law, the id anatomy, the chapter map
- B4 — EchoCachethe ring and the tables the engine uses
- B3 — The Busthe work lanes and the log
- EchoMQ — the coursethe bus the platform rides, in depth
- Functional Programming in Elixirthe functional core the deciders are written in