fivenines
All tracks

Guided learning track

Build Your Own Stock Exchange

A complete electronic trading venue evolved from three-nines operation through five-nines durability and low-latency fairness.

Next up

Orientation · Tutorial 1 of 39

What a stock exchange actually does

20 min · 0% complete
Start tutorial
Full curriculum5 modules · 39 tutorials
01

Orientation

0/3 done

Map the exchange's jobs, full functional surface, and availability budget before building the trading system.

01
Tutorial 120 min

What a stock exchange actually does

Understand an exchange as an ordered market that accepts constrained orders, discovers prices, publishes trades, and hands obligations downstream.

ArticlePracticeDesign
Not startedStart
02
Tutorial 220 min

The full requirements map

Map functional flows, scale, latency, consistency, availability, and recovery requirements before committing to component boundaries.

ArticlePracticeDesign
Not startedStart
03
Tutorial 320 min

Reading the nines: availability as a budget

Convert availability percentages into concrete downtime and failed-request budgets before choosing an architecture.

ArticlePracticeDesign
Not startedStart
02

Three Nines — 99.9%

0/12 done

Build a complete working exchange with deterministic trading, market data, risk, post-trade, scaling, and replay recovery.

04
Tutorial 420 min

Architecture of a complete exchange

Decompose an exchange into order entry, risk, matching, market data, and post-trade boundaries connected by explicit event flows.

ArticlePracticeDesign
Not startedStart
05
Tutorial 520 min

The life of an order

Trace an order through validation, risk, sequencing, matching, acknowledgement, market data, and post-trade processing.

ArticlePracticeDesign
Not startedStart
06
Tutorial 620 min

The order book and price-time priority

Represent bids and asks so the matcher always selects the best price first and preserves arrival order within each price level.

ArticlePracticeDesign
Not startedStart
07
Tutorial 720 min

The order state machine

Encode accepted, active, partially filled, filled, canceled, and rejected transitions so retries cannot produce impossible order states.

ArticlePracticeDesign
Not startedStart
08
Tutorial 820 min

Order types and time in force

Translate order types and time-in-force rules into explicit matching constraints so execution behavior is deterministic and testable.

ArticlePracticeDesign
Not startedStart
09
Tutorial 920 min

Auctions, halts, and safeguards

Use auctions, volatility controls, and trading halts to restore orderly price discovery when continuous matching becomes unsafe.

ArticlePracticeDesign
Not startedStart
10
Tutorial 1020 min

Determinism: the event log is the exchange

Make every matching decision a deterministic function of an ordered event log so replicas can replay and recover identical state.

ArticlePracticeDesign
Not startedStart
11
Tutorial 1120 min

Market data at scale

Publish sequenced snapshots and incremental updates through a fanout path that lets consumers detect gaps and rebuild state.

ArticlePracticeDesign
Not startedStart
12
Tutorial 1220 min

Accounts, custody, and pre-trade risk

Keep matching fast and safe by checking balances, positions, limits, and custody constraints before an order reaches the book.

ArticlePracticeDesign
Not startedStart
13
Tutorial 1320 min

Post-trade: clearing and settlement

Separate execution from clearing and settlement, carrying immutable trades into obligations, netting, and final asset transfer.

ArticlePracticeDesign
Not startedStart
14
Tutorial 1420 min

Scaling to millions of users

Scale participants by partitioning session and market-data fanout while preserving a narrow, deterministically ordered matching core.

ArticlePracticeDesign
Not startedStart
15
Tutorial 1520 min

Operating at three nines: crash, restart, replay

Achieve a credible three-nines baseline by persisting ordered events and rebuilding deterministic state after process crashes.

ArticlePracticeDesign
Not startedStart
03

Four Nines — 99.99%

0/9 done

Remove single points of failure through replicated state, reliable messaging, automatic leadership, overload defense, and multi-site operation.

16
Tutorial 1620 min

The four-nines contract: audit your SPOFs

Audit every critical request path for single points of failure, including hidden dependencies shared across otherwise redundant components.

ArticlePracticeDesign
Not startedStart
17
Tutorial 1720 min

The hot standby: replicated state machines

Replicate an ordered input log to a hot standby so deterministic replay produces a ready-to-promote copy of matching state.

ArticlePracticeDesign
Not startedStart
18
Tutorial 1820 min

Reliable messaging: gaps, NAKs, retransmits

Sequence messages and repair detected gaps with NAKs, retransmission, and snapshots instead of pretending packet delivery is perfect.

ArticlePracticeDesign
Not startedStart
19
Tutorial 1920 min

Sessions that survive failure

Decouple durable session identity and sequence state from individual gateways so clients can reconnect without duplicating or losing orders.

ArticlePracticeDesign
Not startedStart
20
Tutorial 2020 min

Change without downtime

Deploy compatible, reversible changes with canaries, dual-version protocols, and staged migrations so trading continues during upgrades.

ArticlePracticeDesign
Not startedStart
21
Tutorial 2120 min

Deciding who leads: failure detection without split-brain

Combine failure detection, quorum-backed leases, fencing, and epochs so only one matching leader can accept orders.

ArticlePracticeDesign
Not startedStart
22
Tutorial 2220 min

Degrade, don't die: overload protection

Protect order entry and matching with admission control and load shedding, degrading noncritical work before queues collapse.

ArticlePracticeDesign
Not startedStart
23
Tutorial 2320 min

Four nines at scale: multi-zone anatomy

Reach four nines by spreading critical components across zones, removing shared failure domains, and automating bounded failover.

ArticlePracticeDesign
Not startedStart
24
Tutorial 2420 min

The four-nines architecture, assembled

Assemble multi-zone redundancy, automated failover, durable logs, and overload controls into a coherent four-nines exchange.

ArticlePracticeDesign
Not startedStart
04

Five Nines — 99.999%

0/8 done

Apply synchronous durability, regional recovery, cells, gray-failure detection, and safe change to the paths that stop trading.

25
Tutorial 2520 min

Five nines where it counts — and nowhere else

Reserve five-nines engineering for the trading paths whose failure causes the most harm, and give supporting systems cheaper targets.

ArticlePracticeDesign
Not startedStart
26
Tutorial 2620 min

Consensus in the hot path

Keep consensus out of per-order execution where possible, using it to establish ownership while a single leader orders the hot path.

ArticlePracticeDesign
Not startedStart
27
Tutorial 2720 min

Losing a datacenter gracefully

Survive regional loss with preplanned traffic shifts, fenced ownership, replicated state, and explicit recovery-point trade-offs.

ArticlePracticeDesign
Not startedStart
28
Tutorial 2820 min

Cells: capping the blast radius

Partition the exchange into self-contained cells so overload or failure in one market segment cannot consume the whole platform.

ArticlePracticeDesign
Not startedStart
29
Tutorial 2920 min

Gray failures and chaos drills

Expose partial and ambiguous failures with targeted probes and chaos drills that verify detection, isolation, and recovery before production does.

ArticlePracticeDesign
Not startedStart
30
Tutorial 3020 min

The riskiest component is change

Treat deployment as a failure mode and reduce its blast radius with staged rollout, compatibility, observability, and fast rollback.

ArticlePracticeDesign
Not startedStart
31
Tutorial 3120 min

The five-nines architecture, assembled

Assemble cells, multi-region ownership, static stability, and disciplined operations into a five-nines design with bounded failure domains.

ArticlePracticeDesign
Not startedStart
32
Tutorial 3220 min

track: the whole exchange, end to end

Connect order entry, risk, deterministic matching, market data, clearing, and recovery into one end-to-end exchange design.

ArticlePracticeDesign
Not startedStart
05

The Fast Exchange — Milliseconds to Microseconds

0/7 done

Measure and reduce wire-to-wire latency and jitter while preserving durability, fairness, and the availability architecture.

33
Tutorial 3320 min

Latency is a fairness property

Control latency variance across participants because unequal access time can distort price-time priority even when matching is correct.

ArticlePracticeDesign
Not startedStart
34
Tutorial 3420 min

Measuring without lying

Measure end-to-end latency with coordinated timestamps, percentiles, and realistic load so queues and tail behavior remain visible.

ArticlePracticeDesign
Not startedStart
35
Tutorial 3520 min

The millisecond rung: architecture-level latency

Reach millisecond latency by shortening synchronous paths, bounding queues, colocating dependencies, and eliminating avoidable network hops.

ArticlePracticeDesign
Not startedStart
36
Tutorial 3620 min

The microsecond rung: mechanical sympathy

Reach microsecond latency by aligning data layout, CPU affinity, memory access, and network I/O with the hardware's actual costs.

ArticlePracticeDesign
Not startedStart
37
Tutorial 3720 min

Jitter: the tail is the product

Treat tail latency and jitter as first-class outcomes because unpredictable delay undermines both throughput and participant fairness.

ArticlePracticeDesign
Not startedStart
38
Tutorial 3820 min

Fairness engineering

Turn fairness into enforceable ordering rules, synchronized ingress, and auditable timestamps rather than relying on average latency.

ArticlePracticeDesign
Not startedStart
39
Tutorial 3920 min

When nines fight microseconds

Resolve reliability–latency conflicts by keeping the hot path minimal while moving replication and recovery work to carefully bounded boundaries.

ArticlePracticeDesign
Not startedStart