Why Quants Are Switching to Rust
C++ has been the king of HFT for 30 years. But segfaults are expensive. Rust promises C++ speed with Python safety.
The Problem with C++
C++ gives you raw power, but it also gives you a thousand ways to shoot yourself in the foot. Memory leaks, buffer overflows, and race conditions are common. Debugging a production crash in a trading engine that processes millions of orders a second is a nightmare.
The Rust Promise
Rust manages memory at compile time using a system called "Ownership and Borrowing". There is no Garbage Collector (like Java/Python) to pause your program randomly. But there are also no manual malloc/free calls to screw up.
Key Features for Trading
- Performance: Matches C++ in almost every benchmark.
- Fearless Concurrency: The compiler literally won't let you write data races.
- Modern Tooling: Cargo (package manager) is lightyears ahead of CMake.
Code Comparison: Order Matching Engine
Here is a simplified example of how clean a Rust matching engine loop can look compared to C++.
| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | |
| 16 | |
| 17 | |
| 18 | |
| 19 | |
| 20 | |
| 21 | |
| 22 | |
| 23 | |
| 24 | |
| 25 | |
| 26 | |
| 27 | |
| 28 | |
| 29 | |
| 30 | |
| 31 | |
| 32 | |
| 33 | |
| 34 | |
| 35 | |
| 36 | |
| 37 | |
| 38 | |
| 39 | |
| 40 | |
| 41 | |
| 42 | |
| 43 | |
| 44 | |
| 45 | |
| 46 | |
| 47 | |
| 48 | |
| 49 | |
| 50 | |
Who is using it?
While C++ is still dominant (legacy codebases are huge), new projects are increasingly being written in Rust.
- Jump Trading: Heavily invested in Rust for new strategies.
- Hudson River Trading (HRT): Using Rust for internal tools and data pipelines.
- Crypto Firms: Almost entirely Rust (Solana, Polkadot, etc.).