Built from first principles in Rust

A Complete
HFT Infrastructure

A 12.8M match/sec execution engine paired with a distributed vector database for pattern recognition. Two systems. One stack. Zero dependencies on existing infrastructure.

⚡ TITAN — Matching Engine
+
🔷 VAJRA — Vector Database
// sub-microsecond match latency // zero allocations on hot path // raft consensus — independently implemented // HNSW O(log N) approximate nearest neighbour

Data flows through the stack

Orders arrive at Titan's TCP gateway, match at microsecond speed via price-time priority, and emit fill events. Those fills become vectors in Vajra — indexed for semantic pattern search across millions of historical trades.

Two systems. One purpose.

Titan handles execution — price-time priority matching at hardware limits. Vajra handles memory — indexing fills as vectors for pattern recognition. Each is fault-tolerant independently. Together they form a complete system.

TITAN
The Execution Layer
12.8M matches/sec
<78ns P99 latency
0 alloc hot path
  • Lock-free ring buffer for order ingestion — no heap allocation on the critical path
  • Fixed-point arithmetic eliminates floating-point rounding in price comparison
  • Raft consensus for leader election — cluster survives single node failure in <300ms
  • RDTSC-based benchmarking — cycle-accurate latency measurement
  • Cache-line padded ring slots prevent false sharing across cores
View Live Demo →
🔷
VAJRA
The Memory Layer
110 tests passing
O(log N) search
95%+ recall
  • HNSW graph lives entirely in RAM — sub-millisecond approximate nearest neighbour search
  • Write-Ahead Log with CRC32 checksums — survives crash mid-write, recovers on restart
  • Raft consensus with Pre-Vote extension — prevents term inflation during network partitions
  • Biased tokio::select! — heartbeats always fire before client requests, zero false elections
  • gRPC peer-to-peer transport — protobuf-encoded log replication across nodes
View Live Demo →
01
The Problem

HFT systems match fast but have no memory

Modern matching engines are extraordinarily fast — but entirely stateless. They can tell you a trade happened. They cannot tell you if they've seen this price pattern before, or whether a particular order flow precedes a crash. Speed without memory is blind execution.

02
The Architecture

Titan executes. Vajra remembers.

Fill events from Titan become embedding vectors in Vajra. Every matched trade is indexed — price, volume, time, order book state at the moment of match. When a new pattern arrives, Vajra retrieves the 10 most similar historical fills in O(log N) time. The execution layer and the memory layer share the same consensus primitive: Raft.

03
The Decision

Why build both from scratch?

Using Milvus or an existing matching engine would have answered none of the questions I actually had. I wanted to understand why Raft uses Pre-Vote. Why HNSW beats KD-trees at high dimension. Why cache-line padding matters at 12M ops/sec. You only learn that by building it wrong first, then fixing it.

Same instincts. Different problems.

Both systems were designed with the same philosophy: correctness first, then performance, then fault tolerance. The parallel design decisions are not coincidental.

Design Decision ⚡ TITAN 🔷 VAJRA
ConsensusRaft — leader electionRaft + Pre-Vote extension
LanguageRust 1.75+Rust 1.75+
Latency target<100ns P99<1ms P99
Hot path allocationZero — ring bufferZero — HNSW in-place
DurabilityRing buffer snapshotsWAL + CRC32 checksums
Fault toleranceLeader re-election <300msLog replication + recovery
BenchmarkingRDTSC cycle counterCriterion micro-benchmarks
TransportCustom TCP gatewaygRPC + protobuf
Test coverage33 tests — all passing110 tests — all passing
Build systemCargo workspace (8 crates)Cargo workspace (6 crates)

How it came together.

From late-night tinkering to a complete HFT stack.

Nov '24
VAJRA
First HNSW implementation — brute force recall verification against the graph. Understood why approximate nearest neighbour exists.
Dec '24
VAJRA
Raft consensus working. 3-node cluster survives leader crash. Pre-Vote extension added after discovering term inflation bug.
Jan '25
VAJRA
110 tests passing across all 6 crates. WAL corruption recovery, network partition handling, biased reactor — all verified.
Feb '25
TITAN
Ring buffer design started. First attempt used a Vec — 2.1M/sec. Switched to fixed-size lock-free ring — immediately 7× faster.
Mar '25
TITAN
12.8M matches/sec benchmark hit. Cache-line padding eliminated false sharing. Fixed-point arithmetic replaced f64 in price comparison.
Apr '25
TITAN + VAJRA
Unified HFT stack conceptualized. Both projects implement Raft independently. Fill events from Titan map directly to Vajra vector upserts. The system is complete.