24 · Backend architecture
This section states the shape of the system and the properties it must have. It names candidate technologies where it helps, but it does not choose them: the spikes (§29.1) choose, against the criteria in §28, and record why. Any stack that provides the properties below is admissible.
The architecture follows from four facts about this fund: the Record is the product; money moves only through one door; one person must be able to understand the whole thing; and every decision must be replayable years later.
24.1 The shape
┌──────────────────────────────────────────┐
world ──────────▶│ ingest workers (world-readers) │
(data, filings, │ no Record-write credential, egress only │
vendors, news) └────────────────┬─────────────────────────┘
│ raw blobs + parsed rows
┌────────────────▼─────────────────────────┐
│ the Record (append-only event log) │
│ + projections (positions, books, views) │
└───┬──────────────┬────────────────┬──────┘
│ │ │
┌───────────────▼───┐ ┌───────▼────────┐ ┌────▼──────────┐
│ the firm │ │ the kernel │ │ the Floor │
│ seat workers, │ │ pure function │ │ read model + │
│ wakes, debates, │ │ over frozen │ │ signing │
│ Lab, Data desk │ │ inputs │ │ │
└───────────────────┘ └───────┬────────┘ └───────────────┘
│ verdict
┌────────▼─────────┐
│ the gateway │ ← the only broker credential
│ write-ahead, │
│ idempotent │
└────────┬─────────┘
│
brokers / venues
Everything above is a set of processes that can run on one machine and must be able to run on several. Nothing in the design assumes a cluster; nothing in the design prevents one.
24.2 Services and their boundaries
| Service | Owns | Never does |
|---|---|---|
| Record | the event log, projections, the query API, replay | call a model, call a broker, make a decision |
| Ingest | fetching, raw blob storage, parsing, contracts, canaries, health | write artefacts, hold a Record-write credential |
| Manifest assembler | building every seat's inputs by code from queries | accept an input list from a model |
| Seat runner | executing seat calls, schema validation, repair, cost accounting | choose its own inputs, write outside its artefact type |
| Orchestrator | wakes, the calendar, pipeline stages, budgets, retries | bypass a stage, reorder a pipeline |
| Kernel | limit evaluation, verdicts, halt state, order classes | read anything not in its frozen input set |
| Gateway | broker credentials, intents, orders, fills, reconciliation | originate an order, evaluate a limit |
| Scorer | resolution, factor residuals, nulls, calibration, attribution, the scoreboard | be influenced by any model output |
| Floor API | read models, the signing flow, search, the tape | write anything except signed decisions and owner claims |
| Notifier | channels, routing, escalation, heartbeats | carry an action |
- R-ARCH-001 (MUST) These boundaries are enforced by credentials and network policy, not by convention: each service has its own identity, its own least-privilege access to the Record API, and its own outbound allowlist.
- R-ARCH-002 (MUST) The kernel and the gateway are separately deployable, separately audited, and the smallest components in the system. Their code is reviewed line by line by the owner before any live capital, and changes to them are a distinct release class.
- R-ARCH-003 (MUST) No service holds a database connection to another service's store. The Record API is the only data door (R-FUN-023).
24.3 The Record
- R-ARCH-010 (MUST) Append-only event log. Every fact is an immutable, hash-chained event with a type, a payload, a causation id, a correlation id, an actor and a time. Nothing is updated; nothing is deleted. Corrections are compensating events.
- R-ARCH-011 (MUST) Projections are derived and disposable. Positions, books, queues, scoreboards and every Floor screen are projections rebuilt from the log. A projection that cannot be rebuilt from the log is a defect. Rebuild time is measured and reported.
- R-ARCH-012 (MUST) The hash chain is anchored: a periodic signed checkpoint of the chain head is written to append-only storage on a second provider, so tampering is detectable rather than merely improbable.
- R-ARCH-013 (MUST) Event schemas are versioned with explicit upcasters. Replay of a five-year-old event must work against today's code, and a schema change that cannot be upcast is not deployable.
- R-ARCH-014 (MUST) Deterministic identity. Every artefact id is derived from its content and its causation, so a retry cannot create a duplicate and a replay produces the same ids.
- R-ARCH-015 (MUST) The store defaults: a single relational database (PostgreSQL is the obvious candidate) holding the log and the transactional projections; a columnar store for research data; a content-addressed object store for raw blobs; all replicated to object-locked storage at a second provider. The spike may choose otherwise, but a design in which the log and the money projections are not in one transactional store must explain how a fill and a position update stay consistent.
24.4 Time, scheduling and wakes
- R-ARCH-020 (MUST) There is one clock service. No component reads the system clock directly; every timestamp comes from the clock service, which can be driven by the replay engine. This single rule is what makes replay honest.
- R-ARCH-021 (MUST) The wake is the unit of work. A wake is an event with a reason (calendar, trigger, owner, event classifier), a budget, a manifest of what it may read, and a record of its outcome (R-SRC-007). Every wake completes, fails or is cut by budget — never silently vanishes.
- R-ARCH-022 (MUST) The scheduler is durable: schedules live in the Record, a missed schedule is a visible event, and a restart does not lose or double-fire a wake. Cron on a host is not sufficient on its own; whatever is used must satisfy this.
- R-ARCH-023 (MUST) Market calendars, holidays, half-days, settlement dates and time zones live in the security master, not in scheduler configuration.
- R-ARCH-024 (MUST) Every queued task is idempotent on a deterministic key, retried with bounded backoff, and moved to a visible dead-letter state after its cap. Nothing retries forever, and nothing fails invisibly.
- R-ARCH-025 (MUST) Queue default: a durable queue backed by the primary store (a transactional outbox and a job table is sufficient at this scale and keeps one fewer system in the diagram). A broker-based queue is admissible if the spike shows it is needed; it must not become a second source of truth.
24.5 Replay
- R-ARCH-030 (MUST) The replay engine reconstructs any past decision from the log: the same manifest, the same stored model responses (R-MODEL-015), the same data vintages, the same limits, the same clock — and produces the same artefacts and the same verdict, byte for byte.
- R-ARCH-031 (MUST) Replay divergence is a first-class alarm. A nightly job replays a sample of the last period's decisions and reports any divergence; a divergence that is not explained by a declared upcast halts deployment.
- R-ARCH-032 (MUST) Replay is the substrate of the time scrubber (R-UI-040), the incident investigation path, and the "what did we know" question in every review.
24.6 Topology and deployment shape
- R-ARCH-040 (MUST) One composition describes the whole system, and it runs in two profiles: paper (no broker credential present, paper gateway, delayed data) and live (a single gateway instance holding the broker credential). The profiles differ in configuration and credentials, never in code paths.
- R-ARCH-041 (MUST) The gateway is a singleton with a lease: exactly one instance may hold the broker credential, enforced by a lease in the store, and an instance that loses the lease stops placing orders immediately. Two gateways placing orders is the failure mode that costs the most money, so it is made structurally impossible rather than unlikely.
- R-ARCH-042 (MUST) Seat workers are stateless and horizontally scalable; they are the only component whose count changes with load.
- R-ARCH-043 (MUST) The system must run acceptably on a single well-provisioned machine for paper operation, because that is where it will spend most of its first year, and must survive that machine's loss without losing the Record.
- R-ARCH-044 (MUST) Deployment is a versioned artefact: every release has a manifest of component versions, prompt versions, limit versions and schema versions, recorded in the Record, so "what was running" is answerable for any date.
- R-ARCH-045 (MUST) Releases are staged: paper first for a stated soak period, then live, with an automatic halt if a tripwire fires within the soak window. A release cannot skip the soak; skipping requires an owner signature and is reported.
24.7 Secrets and credentials
- R-ARCH-050 (MUST) Every credential lives in a secret store, is scoped to one service identity, has a rotation date, and is never in a repository, an environment file committed anywhere, a log, or a model prompt.
- R-ARCH-051 (MUST) The broker credential is held by the gateway alone, is separate from the owner's own broker login, and is scoped to the minimum the adapter needs. Withdrawal rights are never granted to any credential the fund holds.
- R-ARCH-052 (MUST) Signing keys are per seat and per owner device, held in hardware where the platform allows, and a signature verifies against a key with a known holder and validity window.
- R-ARCH-053 (MUST) Credential use is logged as events: which identity used which credential, when, for what. An unexplained use is a tripwire.
24.8 Observability
- R-ARCH-060 (MUST) Three planes, all rebuilt from or correlated with the Record: metrics (latencies, queue depths, error rates, cost, cache hit rates, canary results), traces (every wake end-to-end, with the correlation id that links a candidate to a fill), and the tape (§22.6), which is the human plane and is the one the owner actually reads.
- R-ARCH-061 (MUST) Every NFR in §3 has a live measurement and an alert, and an NFR without a measurement is not an NFR.
- R-ARCH-062 (MUST) Health is compositional: each connector, each seat, each service and each universe reports healthy / degraded / down with the failing clause named, and a universe's health is computed from its dependencies rather than asserted.
- R-ARCH-063 (MUST) Logs never contain secrets, personal names, or licensed content; this is enforced by a redaction layer that is itself tested.
24.9 Failure and recovery
- R-ARCH-070 (MUST) Fail closed. Any component that cannot verify its inputs, reach its dependencies, or complete its stage stops the pipeline it serves and reports. No stage has a "proceed without" path except where a mandate row explicitly grants one, and those rows are listed on the Floor.
- R-ARCH-071 (MUST) Crash consistency at the money boundary. The gateway writes its intent before
it calls the broker, and on restart reconciles every unresolved intent by querying the broker by
client order id before doing anything else. An
unknownorder state is a halt condition, not a guess (§13). - R-ARCH-072 (MUST) Failure injection is routine: a monthly exercise kills the gateway mid-order, makes a data source lie within its schema, expires a credential, drops the provider for a tier, corrupts a projection and severs the second storage provider. Each has a written expected behaviour; a deviation is a defect with an owner.
- R-ARCH-073 (MUST) Restore is tested, not assumed. A quarterly drill restores the Record from backup into a clean environment, rebuilds every projection, replays a sample period, and compares. The drill's result and its duration are reported; an untested backup is treated as absent.
- R-ARCH-074 (MUST) Recovery objectives are stated and measured: no committed event is ever lost (RPO zero for the Record), and the system is readable again within a stated window after a total host loss. Trading does not resume after a recovery until reconciliation is clean.
24.10 Change
- R-ARCH-080 (MUST) Migrations are forward-only and tested against a copy of production; a migration that cannot be replayed through is not deployable.
- R-ARCH-081 (MUST) Every requirement in this specification has a test that fails when the requirement is violated, and the mapping from requirement id to test is generated, so a requirement without a test is visible (§29.5).
- R-ARCH-082 (MUST) The build is reproducible: the same commit produces the same artefacts, and the running system reports its commit, its schema version and its limits version on the Floor.