Skip to main content

Use this Instead of SQlite on Vercel

· 5 min read
Serhii Hrekov
software engineer, creator, artist, programmer, projects founder

Is SQLite Supported on Vercel? 💾

No, SQLite is not officially supported by Vercel for production applications because of its reliance on the local filesystem. Vercel's serverless functions are stateless and run in a read-only environment, meaning any changes to the local filesystem are discarded after the function's execution. This makes it impossible to persist the SQLite database file between function invocations. Vercel source

While you might be able to get a read-only SQLite database to work by including the database file in your deployment bundle, any attempt to write to it will fail. This limitation makes SQLite unsuitable for most dynamic web applications on the Vercel platform.


Alternatives and Recommendations

If you need a lightweight, file-based database for a Vercel project, the best alternative is a serverless database that is compatible with the platform's stateless architecture. Here are the top alternatives and what I would recommend:

Vercel KV (Key-Value)

For use cases that would traditionally use SQLite for simple data storage or caching, Vercel KV is an excellent serverless alternative. It is a Redis-like key-value store that is fast, scalable, and fully integrated with Vercel's platform. It's ideal for simple data where you don't need complex queries or relationships.

  • When to use: Caching, session management, feature flags. It's the recommended choice for a simple, fast key-value store.

Vercel Postgres (Relational)

If your application requires the features of a relational database, such as tables, joins, and transactional consistency, Vercel Postgres is the direct and recommended alternative. It is a fully managed, serverless PostgreSQL database that handles all the operational complexities for you.

  • When to use: When your data has complex relationships, you need strong data integrity, or you need to perform complex queries. It is the best choice for a traditional relational database on Vercel.

PlanetScale (MySQL)

Another viable alternative is to use an external serverless database like PlanetScale. It provides a serverless MySQL database with features like automatic branching and non-blocking schema changes. It connects to your Vercel project using a standard database connection string.

  • When to use: If you prefer a MySQL database over Postgres and need a serverless solution that handles connection pooling and scaling out of the box.

My Recommendation

If you were considering SQLite for a simple use case like caching or storing temporary user data, Vercel KV is the best alternative. It's built for the Vercel ecosystem and offers superior performance and scalability for those tasks.

If you were looking at SQLite as a quick, small relational database, then Vercel Postgres is the correct choice. It provides the full power of a relational database and is designed to work seamlessly with Vercel's serverless functions, handling all the nuances of connection pooling and cold starts. It is the most robust and secure option for structured data on the platform.