This repository contains a reference implementation of a high-performance Central Limit Order Book exchange system with verifiable settlement capabilities. The system addresses the fundamental tension between execution speed required by market participants and transaction verifiability demanded by regulators through a novel separation of execution and settlement planes.
The system includes a modern web-based frontend built with Next.js, TypeScript, and Tailwind CSS, providing real-time order book visualization and trading capabilities.
The system implements a distributed exchange composed of the following components:
- Ingress-Verifier: Client connection handler with signature validation
- Market-Matcher: Sharded order matching engine
- Settlement-Plane: Asynchronous state checkpoint service
- Message Bus: Redis-based transaction log and communication layer
- Web Interface: Real-time order book visualization and trading interface
- WebSocket Client: For real-time updates
- REST API Client: For order submission and data retrieval
- Separation of Concerns: Execution and verification operate independently
- Horizontal Scalability: Service fleets scale based on workload
- Lock-Free Architecture: Single-threaded market matchers eliminate contention
- Verifiable State Transitions: Cryptographic proofs for all state changes
The execution plane handles order processing with minimal latency:
Ingress Layer:
- TCP-based binary protocol for order submission
- Distributed signature verification farm
- Geographic distribution for latency optimization
Matching Engine:
- Single-threaded per market design
- In-memory order book implementation
- CPU core pinning for deterministic performance
pub fn verify_order_signature(order: &SignedOrder, public_key: &PublicKey) -> bool {
let message = order.to_bytes();
public_key.verify(&message, &order.signature).is_ok()
}The settlement plane provides verifiability without blocking execution:
- Periodic state checkpointing (1-2 second intervals)
- Merkle root calculation for state commitments
- Append-only execution log for audit trail
- Optional TEE attestation for hardware-level verification
Redis serves dual purposes:
- Ultra-low-latency message passing between services
- Durable execution log storage
clob-exchange/
├── clob/ # Backend services
│ ├── crates/
│ │ ├── common-types/ # Core data structures
│ │ ├── matching-engine/ # CLOB logic implementation
│ │ ├── ingress-verifier/ # Client connection handler
│ │ ├── market-matcher/ # Market-specific matching
│ │ ├── settlement-plane/ # Background checkpointing
│ │ ├── verifier/ # Independent audit tool
│ │ ├── configuration/ # System configuration
│ │ └── benchmark-client/ # Performance measurement
│ ├── config.toml # System configuration
│ └── GCP_DEPLOYMENT.md # Production deployment guide
│
└── frontend/ # Web-based trading interface
├── public/ # Static assets
├── src/ # React/TypeScript source
│ ├── components/ # Reusable UI components
│ ├── pages/ # Application views
│ ├── services/ # API clients
│ └── styles/ # Global styles
├── package.json # Frontend dependencies
└── tsconfig.json # TypeScript configuration
Backend:
- Language: Rust (for memory safety and performance)
- Message Bus: Redis (for low-latency communication)
- WebSockets: For real-time market data and order updates
- Optional TEE: Intel SGX / AMD SEV
Frontend:
- Framework: React with TypeScript
- State Management: React Context API
- Styling: CSS Modules or Tailwind CSS
- Real-time Updates: WebSocket client
- Charting: Recharts or similar library for price/volume visualization
Measured on reference hardware:
| Metric | Value |
|---|---|
| Throughput | 3,049 TPS |
| Median Latency (p50) | 1.04ms |
| Tail Latency (p99) | 1.57ms |
| Order Book Capacity | >1M orders |
- Node.js (v16+ recommended)
- npm or yarn package manager
# Install dependencies
cd frontend
npm install
# Start development server
npm run devThe frontend will be available at http://localhost:3000 by default.
- Real-time order book visualization
- Interactive price chart with depth view
- Order placement interface
- Trade history
- Responsive design for desktop and tablet
- Rust toolchain (stable channel)
- Redis server (version 6.0+)
- Minimum 4GB RAM
- Linux environment (recommended)
Step 1: Start Redis
redis-serverStep 2: Launch Backend Services
Terminal 1 - Ingress Verifier:
cd clob
cargo run --release --bin ingress-verifierTerminal 2 - Market Matcher:
cd clob
cargo run --release --bin market-matcher 1Terminal 3 - Settlement Plane:
cd clob
cargo run --release --bin settlement-planeStep 3: Start Frontend Application
Terminal 4 - Frontend:
cd frontend
npm install
npm run devThe web interface will be available at http://localhost:3000
Access the trading interface at http://localhost:3000 to:
- View real-time order book
- Place and cancel orders
- Monitor market activity
Create User Account:
curl -X POST http://127.0.0.1:9090/usersDeposit Funds:
curl -X POST http://127.0.0.1:9090/deposit \
-H "Content-Type: application/json" \
-d '{
"user_id": <USER_ID>,
"asset_id": 1,
"amount": "10000.0"
}'Submit Order via CLI:
cargo run --release --bin benchmark-client <PRIVATE_KEY_HEX> <USER_ID> <MARKET_ID>Execute independent verification:
cargo run --release --bin verifierThe verifier reconstructs system state from the execution log and validates against published state roots.
- Framework: Next.js 14 with App Router
- Language: TypeScript
- Styling: Tailwind CSS
- State Management: React Query + Zustand
- WebSocket: Native WebSocket API
- UI Components: Headless UI + Heroicons
- Real-time order book updates
- Responsive design for desktop and mobile
- Type-safe API client
- WebSocket integration for live updates
- Form validation and error handling
To start the development server:
cd frontend
npm run devTo build for production:
npm run build
npm startLevel 1 - Real-Time Verification: Market participants reconstruct order books from public market data feeds to detect anomalies.
Level 2 - Checkpoint Verification: Light clients verify TEE attestations and state root signatures without transaction replay.
Level 3 - Full Verification: Independent auditors download execution logs and replay all transactions to validate state transitions.
- Retrieve checkpoint data (state root, log ID, attestation)
- Download execution log segment from durable storage
- Replay transactions using reference implementation
- Compare computed state root with published root
- Report discrepancies if detected
Automated multi-service test:
cd clob
cargo test --workspace --test integration_testThis test:
- Launches temporary Redis instance
- Starts all system services
- Executes sample transactions
- Verifies system state
- Tears down test environment
Measure end-to-end latency:
cargo run --release --bin benchmark-client -- --num-traders 4 --duration-secs 30For production deployment on Google Cloud Platform with target throughput of 1M TPS across 21,000 markets.
Key considerations:
- Compact placement policies for minimal network latency
- Dedicated Redis instance on compute-optimized hardware
- Sharded market matcher fleet with core pinning
- Load balancer configuration for traffic distribution
System configuration is defined in config.toml:
- Redis connection parameters
- Network endpoints and ports
- Checkpoint intervals
- Market definitions
- TEE configuration (if enabled)
- Current implementation is for educational/research purposes
- No production-grade authentication/authorization
- Limited error handling in some code paths
- TEE integration is optional and not fully implemented
- Requires manual market shard assignment in production
- Cross-shard atomic swap mechanisms
- Zero-knowledge proof integration for privacy
- Optimistic rollup verification layer
- Hardware acceleration via FPGA/ASIC
- Byzantine fault tolerance for sequencer set
- Full architectural specification:
PRODUCT.md - Deployment guide:
GCP_DEPLOYMENT.md - Repository: https://github.com/yllvar/clob-exchange
This is a reference implementation for educational and research purposes. It is not intended for production use without comprehensive security audits, regulatory compliance review, and proper operational infrastructure.
For technical questions or collaboration inquiries, please open an issue on the GitHub repository.