Under The Hood
frontend bun Bun 1.x (`bun:sqlite`)

bun:sqlite: In-Process C SQLite Bindings vs node-sqlite3 IPC Latency

Last updated
Prerequisites:
SQL and SQLite basics
Node.js native addons (N-API) vs built-in runtime bindings
  • bun
  • sqlite
  • database
  • ffi
  • c-bindings
  • performance

Read at your depth

The practical view

`bun:sqlite` is Bun's built-in, zero-dependency SQLite3 driver: `import { Database } from 'bun:sqlite'`. It provides synchronous, ultra-fast query execution: `const db = new Database('mydb.sqlite')`, `const query = db.query('SELECT * FROM users WHERE id = ?')`, `query.get(1)`. It is 3-6x faster than `better-sqlite3` and `node-sqlite3`.

The same idea in other frameworks

node equivalent
`import Database from 'better-sqlite3'; const db = new Database('db.sqlite');`

Legacy vs modern

Node.js better-sqlite3 vs Bun Native bun:sqlite

External npm SQLite packages require compilation tools (`node-gyp`); `bun:sqlite` is built-in and significantly faster.

before → after
Node.js better-sqlite3 (N-API Dependency)
const Database = require('better-sqlite3'); // ❌ Requires native compile step (node-gyp)
Bun Built-in bun:sqlite
import { Database } from 'bun:sqlite'; // ✅ NEW: Built-in, zero external dependencies

Interview gotchas

Context

Interviewers test your understanding of in-memory / local disk database performance.

The mechanical answer

`bun:sqlite` is **synchronous**. Because SQLite is an in-process, disk/memory database, running queries synchronously in C avoids the overhead of Promise allocations, microtask queue scheduling, and thread context switching. For local SQLite, synchronous execution is significantly faster than asynchronous overhead.

Trap

Do not `await` queries in `bun:sqlite` (`query.get()`, `query.all()` are synchronous methods).

Under The Hood — a multi-depth technical interview hub.

Third-party licenses Press ⌘ K to search.