Does SQLite Work With Vercel?
SQLite works with Vercel but requires careful architecture due to Vercel's stateless, ephemeral serverless environment and lack of persistent filesystem.
Quick Facts
How SQLite Works With Vercel
SQLite can technically run on Vercel's serverless functions, but it's not ideal for most production use cases. Vercel functions are stateless and ephemeral—any SQLite database file written to the filesystem disappears after the function executes. This makes SQLite unsuitable for traditional server-side persistence. However, SQLite shines in two specific scenarios: (1) read-only databases bundled with your deployment for static data queries, and (2) temporary in-memory databases for request-scoped operations. For the bundled approach, you include a pre-built .db file in your deployment, then query it from API routes—perfect for product catalogs or reference data that changes infrequently. For dynamic data that needs persistence, developers must either sync SQLite to an external database (S3, turso, or neon) after writes, or abandon SQLite entirely for Postgres/MongoDB. Edge Functions add another layer of complexity since they run closer to users but have stricter resource constraints and no Node.js filesystem access.
Best Use Cases
Read-Only Bundled SQLite with Vercel Serverless
npm install better-sqlite3import Database from 'better-sqlite3';
import path from 'path';
import { VercelRequest, VercelResponse } from '@vercel/node';
export default function handler(req: VercelRequest, res: VercelResponse) {
try {
// Load pre-built database bundled with deployment
const dbPath = path.join(process.cwd(), 'data.db');
const db = new Database(dbPath, { readonly: true });
const products = db.prepare(
'SELECT id, name, price FROM products LIMIT 10'
).all();
db.close();
res.status(200).json(products);
} catch (error) {
res.status(500).json({ error: error.message });
}
}Known Issues & Gotchas
Filesystem is ephemeral in serverless functions—any writes to SQLite files are lost after the function executes
Fix: Use read-only bundled databases, or sync writes to an external database (Turso, Vercel Postgres, S3). Never rely on local file persistence.
Cold starts add latency when loading large SQLite files into memory on first query
Fix: Keep bundled databases under 5-10MB. For larger datasets, use a proper hosted database. Consider compression or partial data loading.
Edge Functions don't have access to the Node.js filesystem or SQLite3 native bindings
Fix: Stick to Serverless Functions for SQLite usage. Use sql.js (pure JavaScript SQLite) if Edge Functions are required.
Concurrent writes from multiple function instances cause database locks and conflicts
Fix: Never use SQLite for concurrent multi-instance writes on Vercel. Use a proper database backend instead.
Alternatives
- •Vercel Postgres + Node.js pg client: Fully managed, persistent, scales automatically, no filesystem concerns
- •Turso (SQLite Cloud) + libsql client: SQLite compatibility with replication, HTTP API, better suited for Vercel's architecture
- •MongoDB Atlas + mongoose: NoSQL alternative with generous free tier, excellent Vercel integration, no schema constraints
Resources
Related Compatibility Guides
Explore more compatibility guides