Skip to content

ADR 004: Core Engine in Rust

Status

Accepted

Context

InertialEvent requires a high-performance trading core that can detect arbitrage opportunities in sub-millisecond timeframes and execute orders with minimal latency. The system must handle concurrent WebSocket connections, orderbook updates, and order execution without introducing latency from language runtime overhead.

Key constraints: - Sub-millisecond arbitrage detection latency - No garbage collection pauses during critical paths - Memory safety without runtime overhead - Strong type system to prevent common trading bugs

Decision

Implement the trading core in Rust.

Rationale

  • No garbage collection pauses: Critical for sub-millisecond latency requirements
  • Memory safety without runtime overhead: Ownership model prevents data races at compile time
  • Excellent async ecosystem: Tokio provides battle-tested async runtime
  • Proven in reference implementation: Polymarket-Kalshi-Arbitrage bot demonstrates viability
  • Strong type system: Prevents common trading bugs like incorrect side/price handling

Alternatives Considered

Language Pros Cons Verdict
Rust No GC, memory safe, excellent async Learning curve Chosen
C++ Maximum performance Memory safety concerns, harder to hire Rejected
Go Simple concurrency model GC pauses during critical paths Rejected
Python Rapid development, many trading libraries Too slow for latency-critical paths Rejected (control layer only)

Consequences

Positive

  • Sub-millisecond orderbook processing achievable
  • Memory safety guarantees without runtime overhead
  • Rich ecosystem for WebSocket, HTTP, and cryptographic operations
  • Strong compile-time guarantees reduce runtime bugs

Negative

  • Rust learning curve for team members unfamiliar with ownership model
  • Longer initial development time compared to Python/Go
  • Some library ecosystem gaps compared to more mature languages

Neutral

  • Need to maintain both Rust (core) and Python (Telegram bot) codebases

References

Linked Requirements

  • NFR-ARCH-001: Core engine must be implemented in Rust