Design a low-latency trading system
System Design: Low-Latency Electronic Trading Platform (Equities)
Problem Description
Design a single-region electronic trading platform (similar to an exchange or ATS) that supports market and limit orders for equities. The system must accommodate co-located clients within the same region and prioritize high determinism, strict auditability, and robust failure handling.
Requirements
1. Order Books and Matching
- Maintain a separate order book for each financial symbol.
- Implement a price-time priority matching engine, ensuring FIFO (First-In, First-Out) within each price level.
2. Market Data Ingest and Publish
- Ingest and normalize market data from multiple external venues.
- Publish market data for your platform (both snapshots and incremental updates) with bounded skew across different symbols or shards.
3. Client Interfaces
- Expose authenticated APIs for order entry, supporting both REST and/or gRPC protocols.
- Provide a dedicated low-latency streaming protocol for market data dissemination.
4. Risk, Idempotency, and Reports
- Perform comprehensive pre-trade risk checks, including credit limits, position limits, and price bands.
- Ensure that all order submissions are idempotent.
- Provide exactly-once execution reports to clients.
5. Performance and Scale
- Achieve a P99 end-to-end acknowledgement latency of under 5 milliseconds within the single operational region.
- The system must handle a peak throughput of 200,000 orders per second.
- Design for horizontal scalability to accommodate bursts in order volume beyond the steady-state peak.
6. Persistence and Auditability
- Persist all system state using an append-only log or an event sourcing pattern.
- Support deterministic replay and backtesting capabilities.
- Maintain strict audit trails for all operations.
7. Trading Scenarios
- Correctly handle complex trading scenarios, including partial fills, order cancellations, mass cancellations, auctions, market halts, and symbol pauses.
8. Partitioning, Concurrency, and Recovery
- Design the partitioning and sharding strategy for order books.
- Define the concurrency control mechanisms within the matching engine.
- Support robust recovery and disaster recovery, aiming for a Recovery Point Objective (RPO) of approximately 0 and a Recovery Time Objective (RTO) of less than 1 minute.
9. Reliability and Fairness
- Address fault tolerance mechanisms.
- Implement time synchronization and manage clock skew (e.g., using PTP).
- Ensure fairness across different partitions.
- Incorporate backpressure and flow control strategies.
10. Operability
- Define comprehensive monitoring strategies and Service Level Objectives (SLOs).
- Plan for capacity and implement strategies to test latency and correctness under various failure conditions.
Assumptions
- Orders are day-only, with a minimum tick size of $0.01. The system should be extensible if needed.
- Clients are authenticated institutional participants.
- The primary production environment consists of one region with multiple Availability Zones (AZs). An optional warm-standby region is available for disaster recovery.
AI interview prep
Core dilemma
Balancing ultra-low latency and extreme throughput with strict consistency, determinism, and auditability in a distributed financial system, while ensuring high availability and disaster recovery with near-zero data loss.
3 tradeoffs and 3 stress tests locked
Interview prep
Unlock the interviewer X-Ray rubric, tradeoff matrix, stress tests, clarifying questions, and key concepts.
Design a low-latency trading system
System Design: Low-Latency Electronic Trading Platform (Equities)
Problem Description
Design a single-region electronic trading platform (similar to an exchange or ATS) that supports market and limit orders for equities. The system must accommodate co-located clients within the same region and prioritize high determinism, strict auditability, and robust failure handling.
Requirements
1. Order Books and Matching
- Maintain a separate order book for each financial symbol.
- Implement a price-time priority matching engine, ensuring FIFO (First-In, First-Out) within each price level.
2. Market Data Ingest and Publish
- Ingest and normalize market data from multiple external venues.
- Publish market data for your platform (both snapshots and incremental updates) with bounded skew across different symbols or shards.
3. Client Interfaces
- Expose authenticated APIs for order entry, supporting both REST and/or gRPC protocols.
- Provide a dedicated low-latency streaming protocol for market data dissemination.
4. Risk, Idempotency, and Reports
- Perform comprehensive pre-trade risk checks, including credit limits, position limits, and price bands.
- Ensure that all order submissions are idempotent.
- Provide exactly-once execution reports to clients.
5. Performance and Scale
- Achieve a P99 end-to-end acknowledgement latency of under 5 milliseconds within the single operational region.
- The system must handle a peak throughput of 200,000 orders per second.
- Design for horizontal scalability to accommodate bursts in order volume beyond the steady-state peak.
6. Persistence and Auditability
- Persist all system state using an append-only log or an event sourcing pattern.
- Support deterministic replay and backtesting capabilities.
- Maintain strict audit trails for all operations.
7. Trading Scenarios
- Correctly handle complex trading scenarios, including partial fills, order cancellations, mass cancellations, auctions, market halts, and symbol pauses.
8. Partitioning, Concurrency, and Recovery
- Design the partitioning and sharding strategy for order books.
- Define the concurrency control mechanisms within the matching engine.
- Support robust recovery and disaster recovery, aiming for a Recovery Point Objective (RPO) of approximately 0 and a Recovery Time Objective (RTO) of less than 1 minute.
9. Reliability and Fairness
- Address fault tolerance mechanisms.
- Implement time synchronization and manage clock skew (e.g., using PTP).
- Ensure fairness across different partitions.
- Incorporate backpressure and flow control strategies.
10. Operability
- Define comprehensive monitoring strategies and Service Level Objectives (SLOs).
- Plan for capacity and implement strategies to test latency and correctness under various failure conditions.
Assumptions
- Orders are day-only, with a minimum tick size of $0.01. The system should be extensible if needed.
- Clients are authenticated institutional participants.
- The primary production environment consists of one region with multiple Availability Zones (AZs). An optional warm-standby region is available for disaster recovery.