Introduction

StarbaseDB is an open-source, scale-to-zero, HTTP SQLite database built on top of Cloudflare Durable Objects.

Bundled as part of the database offering are tools to help expedite your developer experience. Interact with your data source without the unnecessary use of requiring third party tools to be configured. Instead, utilize the built-in REST API’s, web socket connections, HTTP endpoints and more already pre-configured for your database.

Whether you are building out a small project or a larger production-ready product, StarbaseDB can be an ideal choice for your team.

Currently, a paying Cloudflare account is required to self-deploy a database instance. Durable Objects with SQLite storage are not available on the free tier at this time. Plans start at $5/mo.


Features

Included at the time of deployment for you to quickly get started:

HTTP API

Execute queries and transactions via our built-in API for quick query & response interaction.

REST API

Interact with your SQL tables with our CRUD endpoints made available to you by default.

Web Sockets

Create web socket connections for low-latency querying and event listening.

Import & Export

You can both export and import into your database with data from a SQL dump, JSON or CSV.

Database GUI

View, query, and edit your database with Outerbase Studio which comes with each StarbaseDB deployment.

Key Benefits

Having your database and application logic co-located on the same machine enables incredibly powerful and fast multi-purpose use cases. StarbaseDB instances get the automatic benefit of being hosted on Cloudflare and their world-class compute and globally distributed network to ensure your users have their resources located closest to them for fastest performance.

Zero-latency Queries

Traditional databases when queried are usually issued over a network call from application code located somewhere on the planet and that query request has to make a round-trip from the application logic to the database.

StarbaseDB (thanks to Cloudflare’s SQLite in Durable Objects) does not need to make a round-trip from our exposed interaction methods to a database. Instead, the SQLite data source runs not just on the same machine as a Durable Object, not just in the same process, but in the very same thread [1]. Because there is no communication barrier between the application and SQLite, our latency is effectively zero.

Instead of queries being measured in milliseconds, we can now measure them in microseconds.

Synchronous Queries

Continuing from the section above and noting how Durable Objects and Workers are running on the same exact thread, this means that any time we execute a SQL query it is ran synchronously by design. Due to the nature of how the low-level aspects of the system operates we can develop with the assumption that our data should already be cached in memory.

Synchronous queries mean fast responses.

N+1 Selects

Most database engines suffer from the classic N+1 query problem, where you must first query for a set of data, and then subsequently iterate over each individual item for more data or construct a dynamically complex encompassing query. Because StarbaseDB is a zero-latency database we no longer have to worry about the speed issues traditional databases present when running N+1 queries. We can safely construct easy to read queries and loops and get nearly the same performance without the hassle.

An example provided in a blog post by Cloudflare shows how we can write clean code safely iterating an array and executing a query on each loop synchronously.

// N+1 SELECTs example

// Get the 100 most-recently-modified docs.
let docs = sql.exec(`
  SELECT title, authorId FROM documents
  ORDER BY lastModified DESC
  LIMIT 100
`).toArray();

// For each returned document, get the author name from the users table.
for (let doc of docs) {
  doc.authorName = sql.exec(
      "SELECT name FROM users WHERE id = ?", doc.authorId).one().name;
}

Interfaces by default

Out of the box we provide all of the most popular ways a developer would want to interact with their database with zero setup. As we will exhaustively cover throughout the rest of the documentation, you can quickly view your database in a provided hosted user interface right on top of your database thanks to the open-source Outerbase Studio library. Additionally developers can use our HTTP endpoints to query the database, web sockets for low-latency querying which is great for executing large numbers of queries, REST API to interact with your tables in a safe CRUD exchange, and import & export your data directly to or from your database.

We want to be the most developer friendly SQLite offering on the planet.

Compared to Cloudflare D1

Cloudflare provides a managed SQLite database offering named D1. Their offering is similarly built on top of Cloudflare’s architecture and global network and is designed as a managed database instance. You can think of it similarly to other managed databases and providers such as AWS, DigitalOcean, Neon, Turso and others – but for SQLite.

StarbaseDB utilizes Cloudflare’s Workers for compute and Durable Objects for SQLite storage. In addition to the great architecture already in place, StarbaseDB allows you to co-locate your application layer logic directly on top of where your data is stored. What that means is the Worker that handles all of the compute (such as our REST API’s) executes queries in a synchronous manner providing responses incredibly fast.

The primary difference between StarbaseDB and D1 is the number of tools provided out of the box and the ability to customize the code that runs on your Worker to continue building onto and adding more application logic right where your database is deployed.

Join our Community

When it comes to building a product people love, we want to build it with the people. With our open-source project we welcome all ideas, questions, requests and issues.

Discord Community

Ask questions & discuss changes with our community.

Github Repo

Contribute to our project, open issues, and learn more.

Updated on