Why We’re Rewriting SQLite in Rust by Glauber Costa

ScyllaDB 0 views 35 slides Oct 09, 2025
Slide 1
Slide 1 of 35
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28
Slide 29
29
Slide 30
30
Slide 31
31
Slide 32
32
Slide 33
33
Slide 34
34
Slide 35
35

About This Presentation

As we were adding Vector Search to SQLite, we had a crazy idea. What could we achieve if we were to completely rewrite SQLite in Rust? This talk explains what drove us down this path, how we’re using deterministic simulation testing to ensure the reliability of the Rust rewrite, and the lessons le...


Slide Content

A ScyllaDB Community
Why We’re Rewriting
SQLite in Rust
Glauber Costa
CEO

Glauber Costa

Founder/CEO - Turso
■Linux Kernel contributor
■VP Field Engineering at ScyllaDB
■Staff Engineer at Datadog
■Founder of Turso

Why Rust?

Why Rust specifically?
It could have worked in Zig.
Ultimately, whatever works.
Team was very familiar with Rust.
But ultimately, the borrow checker!

Why rewrite the most deployed
database in the solar system?

Can the best be better?
■SQLite is great for reads, but writes are painful: single writer.
■SQLite is hard to extend. Extensions exist, but:
■Not memory-safe,
■Can’t add new index types,
■Can’t add new data types and affinities,
■Can’t influence the language syntax.
■Lacks modern features like CDC, Encryption, Vector Search.

Can the best be better?
■SQLite is great for reads, but writes are painful: single writer.
■SQLite is hard to extend. Extensions exist, but:
■Not memory-safe,
■Can’t add new index types,
■Can’t add new data types and affinities,
■Can’t influence the language syntax.
■Lacks modern features like CDC, Encryption, Vector Search.

SQLite - Open Source, Not Open Contribution
Small and restricted team of contributors.
Contributions not accepted, or rarely accepted.
Test suite is legendary, but also proprietary.

Every rewrite is an opportunity
■New async architecture.
■Concurrent writes, solving the notorious “database is locked” problem.
■Deterministic Simulation Testing from day1 to match SQLite’s reliability.

This is a performance conf!

Async
Multithreading
Incrementalism

Asynchronous interface
SQLite’s C API is synchronous
Meaning I/O is synchronous.

Turso on Linux: io_uring: asynchronous fsync.

MVCC

MVCC (Multi-Version Concurrency Control)
●MVCC: Optimistic concurrency control.
●Transactions that do not conflict can proceed in parallel.
●Conflict resolution at COMMIT time.
●Async fsync makes sure the next transactions can start already.

MVCC in Turso
●Lifting the single-writer limitation.
●Concurrent transactions can progress independently until they commit.

SQLite parallel write behavior
●Writing batches of 10 rows, with a 1ms think time in the transaction:

BEGIN;
Insert <row1>

call_an_api(1ms);

INSERT <row10>
COMMIT;

SQLite vs Turso write throughput
10 rows per transaction
1 ms simulated think time

SQLite write throughput

Multi-threading

Threads are… fine ?

The hierarchy of evil
Def.Evil
Maybe a bit evil
Not Evil

Threads

Opening a new connection: O(N) on tables.

Opening a new connection: O(N) on tables.

Opening a new connection: O(1) on tables.

Opening a new connection: O(1) on tables.

Incrementalism

SQLite schema changes
sqlite> create table foo(bar);
sqlite> create index bar_i on foo(bar);
sqlite> select * from sqlite_master;
table|foo|foo|2|CREATE TABLE foo(bar)
index|bar_i|foo|3|CREATE INDEX bar_i on foo(bar)
-- a new change now will reparse the entire schema!

Turso schema changes are incremental

Live Materialized Views

How Materialized Views work

Materialized Views on an in-process database?

DBSP

DBSP

Conclusion:
●We believe SQLite needs a facelift to power modern applications.
●Turso is an Open Contribution rewrite of SQLite.
●Even on performance, there is a lot of room for improvement.
●Perf improvements are architectural, not language-derived.
●Foundation is: Async I/O, multithreading, and incrementalism.

Thank you! Let’s connect.
Glauber Costa
[email protected]
@glcst
blog.turso.tech
github.com/tursodatabase/turso
Tags