How Exchanges Turn Order Books into Distributed Logs
5 days ago
- #low-latency
- #market-microstructure
- #distributed-systems
- Exchanges transform high-frequency chaos into a single deterministic timeline using distributed logs.
- Order books are structured as distributed logs to ensure fairness and deterministic ordering.
- The core challenge is converting concurrent events from different sources into a globally agreed sequence.
- Timestamps alone are insufficient due to clock drifts and lack of a global 'now' in distributed systems.
- Modern exchanges use a pipeline: Gateway → Sequencer → Matching Engine to assign sequence numbers.
- The sequencer assigns monotonically increasing sequence numbers to create a total order of events.
- The matching engine applies events deterministically, ensuring the order book is a real-time projection of the log.
- The log is append-only, replayable, and auditable, making it the source of truth.
- Reduction operations transform the linear log into a hierarchical order book with price-time priority.
- Deterministic ordering ensures fairness but introduces a performance bottleneck at the sequencer.
- Exchanges optimize for low latency using kernel bypass, batching, cache locality, and NUMA pinning.
- Eventual consistency is impossible in trading systems due to the need for strict ordering.
- Replication strategies ensure fault tolerance without adding latency to the sequencing path.
- Snapshots are used to make log replay practical by periodically dumping the in-memory book state.
- The log model provides fairness, determinism, auditability, simplicity, and recovery capabilities.