How Rust Is Rewriting Databases (TiKV, FoundationDB Clients, Materialize)
There was a moment in 2021 when I realized Rust wasn’t “just a language” anymore.
I was debugging a microservice where our storage stack was doing mental gymnastics — partial failures, async replication, data races in Go code, and a write-path bottleneck that only appeared under 50k QPS load.
Then someone from SRE casually said: “Have you looked at Rust-based KV engines? TiKV’s write path never corrupted under crash loops.”
That was the day reality snapped: databases are being rewritten in Rust — not as a hype experiment, but because old languages literally can’t handle the new physics of distributed data.
Today it’s not “Will Rust rewrite databases?” It’s: Which database will be the next one rewritten?
Why Databases Need Rust Databases need three properties that languages like C/C++ struggled to balance: | Need | Why it matters | Why Rust wins | | ---------------------------- | ---------------------------------------------- | ----------------------------------------- | | Memory safety | DB corruption = existential failure | Rust enforces correctness at compile time | | Predictable performance | Low-latency, sub-ms reads, no GC spikes | Zero-cost abstractions, no GC pauses | | Concurrency without hell. | Multi-core, async IO, lockless data structures | Ownership + Send/Sync = safe concurrency | The modern DB problem is not “fast SQL”. It’s safe, distributed, crash-resistant consensus under stupid-high throughput. That’s Rust’s playground.
Case Study 1: TiKV — The Rust Heart of TiDB Think “open-source Google Spanner”, but written in Rust. TiKV is:
- Distributed key-value store
- Raft-based
- RocksDB storage engine
- Foundation for TiDB (MySQL-compatible distributed SQL database)
Every TiDB transaction touches Rust code. Every. Single. One. Why they picked Rust From TiKV engineers: “We needed C++ performance without C++ footguns.” That’s not a tagline — it’s survival. TiKV Write Path (Simplified) Client
→ SQL Layer (TiDB)
→ KV transaction
→ Raft leader append
→ RocksDB write
→ Replicate to followers
→ Commit + Ack
Tiny but scary-real Rust snippet — Raft entry apply fn apply_entries(&mut self, entries: &[Entry]) {
for entry in entries {
if let EntryType::Normal = entry.get_type() {
let cmd = parse_command(entry.data());
self.storage.apply(cmd);
}
}
} No panic. No segfaults. Just predictable, safe, distributed state machine replication.
Case Study 2: FoundationDB’s Rust Client FoundationDB = Apple’s internal database for everything mission-critical. When Apple adopted Rust for FDB client bindings, it was a quiet but nuclear moment.
FoundationDB engineers don’t care about hype. They care about:
- correctness guarantees
- linearizable transactions
- tail-latency discipline
- no silent corruption ever
A real Rust FDB snippet let db = fdb::Database::default()?; let trx = db.create_trx()?; trx.set(b"user:1", b"hello-rust"); trx.commit().await?;
Tiny code, huge trust model. If that call silently corrupted data? Apple’s internal infra would burn. Rust earned that trust.
Case Study 3: Materialize — Streaming SQL Engine Materialize does incremental streaming SQL. Kafka streams in. SQL view updates live. Sub-100ms update latency.
Why Rust?
- Hot path performance
- Finite state machines that cannot crash
- Multi-threaded compute, no GC surprise
Dataflow Architecture [KAFKA] -> [Decode] -> [Timely Dataflow] -> [Materialized View Cache] -> SQL query Code Flow: Stream operator in Rust stream.map(|event| {
let parsed = parse_event(event)?; update_state(parsed)
})
Streaming SQL engines hate unpredictable latency. Rust gives deterministic cost — nothing else in mainstream does that today. Why C, Go, and Java Aren’t Enough Anymore | Language | Blocker for DB engines | | -------- | --------------------------------------------- | | C/C++ | Memory unsafety, undefined behavior landmines | | Go | GC jitter, pointer sharing, lock contention | | Java | GC, JIT warm-up, latency unpredictability |
The old world assumed vertical scaling and monolithic databases. The new world demands:
- distributed consensus
- lock-free structures
- 100k+ connections
- persistent memory
- async IO
- zero-tolerance for corruption
Rust is exactly the language designed for this era. Architecture Diagram: Rust Database Engine Layers ┌───────────────┐
│ Client API │ ← Rust SDK
├───────────────┤
│ Transaction │ ← MVCC, snapshots
├───────────────┤
│ Consensus │ ← Raft / Paxos in Rust
├───────────────┤
│ Storage Engine│ ← RocksDB / custom Rust engine
├───────────────┤
│ WAL + IO │ ← Zero-copy, io_uring, async
└───────────────┘
This stack used to be C++ territory. Rust walked in and said: “You can have speed and safety.” And DB engineers said: “Finally.” The Emotional Truth Nobody Admits** Writing DB engines in C++ feels like defusing bombs blindfolded. Writing them in Go feels like negotiating with a garbage collector demon. Rust feels like: ✅ Brutal at compile time ✅ Gentle at runtime ✅ Honest about correctness ✅ Rewarding under pressure This isn’t language fandom. It’s the sober choice when your job is “don’t lose data.”
What Comes Next: Rust DB Revolution Roadmap Emerging Rust-native DBs & engines: | Project | Type | | -------------- | ----------------------------- | | RisingWave | streaming DB | | SurrealDB | real-time graph / document DB | | SeaDB. | SQL engine | | GlueSQL. | embeddable SQL | | GreptimeDB. | time-series DB |
Future rumors?
- Postgres extensions in Rust
- Mongo rewrite paths
- Redis-like Rust engines
- Edge-native distributed SQLite with Rust WAL
If you think only early adopters do this — remember Cloudflare, Discord, AWS, and Apple already committed.
Final Thought Databases are the truth layer of the internet. We can tolerate flaky UI frameworks. We can tolerate slow CI pipelines. We cannot tolerate data corruption. Rust isn’t winning because it’s cool. Rust is winning because data deserves armor. This decade isn’t “Rust hype.” It’s Rust infrastructure consolidation. And one day we’ll look back and say: “The moment databases moved to Rust was the moment reliability finally became mainstream.”