Fulcrum is a high-performance, event-driven financial exchange simulator engineered for microsecond-level latency and high-throughput order processing. The project explores the core challenges of financial technology, leveraging a distributed microservices architecture with Rust for the matching engine and Go for concurrent network services.
The system comprises decoupled, specialized microservices communicating asynchronously via a central message bus (Kafka). This architecture ensures resilience, scalability, and clear separation of concerns.
graph TD
subgraph Client
A[gRPC Client]
end
subgraph Backend Services
B(Order Gateway - Go) -- gRPC --> A
C(Matching Engine - Rust)
D(Market Data Distributor - Go)
E(Clearing & Settlement - Go)
end
subgraph Message Bus
K[Apache Kafka]
end
subgraph Database
P[PostgreSQL]
end
subgraph Frontend
W[WebSocket Client]
end
A -->|"1. SubmitOrder Request"| B
B -->|"2. Publishes Order"| K(orders topic)
K(orders topic) -->|"3. Consumes Order"| C
C -->|"4. Publishes Trade"| K2(trades topic)
K2 -->|"5. Consumes Trade"| D
K2 -->|"6. Consumes Trade"| E
D -->|"7. Broadcasts Trade"| W
E -->|"8. Persists Trade"| P
-
Low-Latency Matching Engine
Developed in Rust for predictable, microsecond-level performance using a price-time priority algorithm. -
Event-Driven Architecture
Microservices are decoupled and communicate asynchronously via Kafka, ensuring resilience and scalability. -
High-Performance API
The Order Gateway exposes a gRPC API for efficient, low-latency order submission. -
Real-Time Market Data
The Market Data Distributor broadcasts trade events instantly to clients using WebSockets. -
Durable Settlement
The Clearing & Settlement service persists all executed trades in PostgreSQL for auditing and compliance.
| Component | Technology | Rationale |
|---|---|---|
| Matching Engine | Rust (Tokio) | Zero-cost abstractions, no garbage collector, predictable low-latency execution |
| Network Services | Go | Excellent concurrency model for high-throughput I/O-bound tasks |
| API & Communication | gRPC, Protobuf | High-performance, language-agnostic RPC framework |
| Messaging / Event Bus | Apache Kafka | Durable, scalable, high-throughput message queue for service decoupling |
| Database | PostgreSQL | ACID-compliant relational DB for reliable trade persistence |
| Real-Time Frontend | WebSockets | Bi-directional protocol for instant market data broadcasting |
| Containerization | Docker | Portable, reproducible environments for every service |
| Orchestration | Kubernetes (Planned) | Automated deployment, scaling, and management of containers |
Follow these steps to set up and run the system locally.
Ensure the following tools are installed:
- Rust & Cargo – for the Matching Engine
- Go – for Order Gateway, Market Data, and Settlement services
- Docker & Docker Compose – to run Kafka and PostgreSQL
- Protobuf Compiler (protoc) – to compile gRPC service definitions
- grpcurl – for testing the gRPC API
- wscat – for testing WebSocket connections
Start each service from the project’s root directory in separate terminal windows.
docker compose upcargo run --bin matching-enginego run ./services/order-gateway-go/cmd/main.gogo run ./services/market-data-go/cmd/main.gogo run ./services/clearing-settlement-go/cmd/main.goConnect to the Market Data Distributor to view real-time trades:
wscat -c ws://localhost:8080/wsSend a SELL order to rest on the book:
grpcurl -plaintext -proto ./proto/v1/order.proto -d '{"user_id": "seller-789", "symbol": "AAPL", "quantity": 10.0, "price": 150.00, "side": "SELL"}' localhost:50051 v1.OrderService/SubmitOrderSend a matching BUY order to create a trade:
grpcurl -plaintext -proto ./proto/v1/order.proto -d '{"user_id": "buyer-123", "symbol": "AAPL", "quantity": 5.0, "price": 150.00, "side": "BUY"}' localhost:50051 v1.OrderService/SubmitOrderTrade data will appear instantly in your WebSocket client (Terminal 6). You can also verify trade records in the PostgreSQL database, persisted by the settlement service.