NEW

SurrealDB 4 is here, introducing SurrealDB Earth and SurrealDS!

Learn more

One isolated database per agent or customer

Engineering

Nov 17, 20267 min read

Tobie Morgan Hitchcock

Tobie Morgan Hitchcock

Show all postsOne isolated database per agent or customer

Our newsletter

Get tutorials, AI agent recipes, webinars, and early product updates in your inbox every two weeks

Giving every user, customer or agent a database of its own is an old idea that more and more software now uses. Agent software suits it well: each agent's memory, state and permissions belong to one agent, one user or one customer, and they are safest in a place that no other tenant can reach.

This post explains why the pattern works, why it has been hard to afford, and how SurrealDB Earth, launched on 3 November 2026 with SurrealDB 4, makes it practical. A database on Earth starts on its first query, scales to zero when nobody uses it, and is billed by usage instead of by idle servers.

An agent accumulates state: conversation history, tool results, learned preferences and working notes. In one shared database, every query has to carry a tenant filter, and a single missed filter returns another tenant's data. With a database for each tenant, the boundary is the database itself, so a query can only see the data of the database it is connected to.

This pattern is becoming frequently used in the industry, with Bluesky a prominent example of a social network that uses this pattern at scale. Each account on its personal data servers has its own SQLite database, so a server holds many small, single-tenant databases instead of one large shared one.

The pattern gives you these properties:

  • Isolation by construction. A query reads and writes only the database it is connected to.

  • A simple lifecycle. Adding a customer adds a database, and removing a customer removes their database and everything in it, which also makes a request to erase a customer's data straightforward.

  • Credentials with a small reach. A user or access method defined on one database cannot sign in to another, so a leaked credential exposes one tenant at most.

  • Independent schema. Each agent or customer can add its own tables and indexes without affecting the others.

  • Clear cost attribution. Usage maps to one agent or one customer.

If one database per customer is such a convenient pattern, why is it not more universally used? The reason is simple: because most databases charge for a running server whether or not anyone is querying it. A server for each agent means thousands of servers that are idle most of the time, so teams have usually accepted one shared database with tenant filters, even when a database for each tenant was the design they wanted.

SurrealDB Earth is serverless SurrealDB, built on Cloudflare Durable Objects and R2. Three properties remove the cost of idle databases:

  • A database starts with its first query. Creating an instance takes about 500ms, and a cold start currently takes about 300ms.

  • An idle instance scales to zero shortly after its last request.

  • Billing follows usage, so a database that nobody queries has no server running.

Earth gives you two levels at which to separate tenants.

An Earth instance is the deployment that you create in Studio or with the surreal cloud CLI. Each instance has its own storage and its own commit log, and its tokens are signed with its own key, so a token issued for one instance fails verification on every other instance. Each instance also has its own data residency, network policy and capabilities.

Inside an instance, each database sits in a namespace, and Earth creates the namespace and the database on the first request that uses them. Databases in one instance share the instance's storage, commit log and compute, and SurrealDB's namespace and database permissions keep their data apart.

The two levels suit different cases:

A database for each tenantAn instance for each tenant
CreatedOn the first request that names itIn Studio, with the CLI or with the Cloud API
Separate storage and commit logNo, shared within the instanceYes
Separate data residency and network policyNoYes, such as EU data for one customer and US data for another
A transaction across several tenantsPossible, within one instanceNot possible
Number on Earth FreeMany in one instanceUp to 100 instances

Most applications can start with one instance and a database for each tenant, and move a tenant to an instance of its own when it needs its own region or its own policies.

Use a namespace for the application and a database for each user, customer or agent. A session selects them with USE:

-- A database for each user of the application `my_app`
USE NS my_app DB randalthor;
CREATE note CONTENT { text: 'Practise the Spanish past tense' };

USE NS my_app DB lordofSalty;
CREATE note CONTENT { text: 'Book a lesson for Friday' };
-- Only the note in this user's database
SELECT VALUE text FROM note;
Output
['Book a lesson for Friday']

Neither database has to exist beforehand, because the first request that names one creates it. In practice, name each database after a stable identifier, such as a user ID, rather than after a name that the user can change.

An SDK selects the namespace and database in the same way when it connects. To try the same thing from a terminal, open a shell on one tenant's database with the surreal cloud CLI:

surreal cloud instance sql my-app --namespace my_app --database randalthor

Earth bills three meters: requests, storage and active hours. The SurrealDB pricing page always has the latest figures.

FreePro
Price$0, with only an email address to sign up$15 a month per account, at its launch price
Requests a month3M10M
Storage10 GB25 GB
Active hours a month1001,000
Earth instancesUp to 100Unlimited
At a limitPauses, and keeps your dataKeeps running and bills the usage

Above the Pro allowance, requests cost $0.65 per 1M, storage costs $0.25 per GB-month and active hours cost $0.05 per hour. Egress is unlimited on both plans.

Active hours measure how long an instance's compute runs, added up over all of its cells, so an instance that has scaled to zero uses none.

Take a language learning app with 10,000 learners on Earth Pro. Each learner has their own database in one Earth instance, and the figures below are an illustration rather than a measurement:

  • Each learner studies about 15 times a month, and a session sends about 60 requests, which is 9M requests in total.

  • Each learner's vocabulary, progress and notes take about 2 MB, which is 20 GB in total.

  • Learners in different time zones keep the instance busy for most of the day, which comes to about 1,100 active hours.

MeterUsedIncluded in ProBilled
Requests9M10M$0.00
Storage20 GB25 GB$0.00
Active hours1,1001,000100 hours at $0.05, which is $5.00
Plan$15.00
Total$20.00 a month

That is $20 a month for 10,000 separate databases, or $0.002 per learner. The pricing page lists requests as request units, and a query that reads or writes a lot of data can cost more than one unit, so measure your own app before relying on the request count.

On Earth Free, the same app pauses when it reaches the free allowance and keeps all of its data, and Free never sends a bill.

A database for each agent, user or customer keeps every tenant's data, credentials and schema apart, and turns adding or removing a tenant into creating or removing a database. On Earth, a database starts with its first query and costs nothing while it is idle, so the pattern no longer needs a server for each tenant. Start with one instance and a database for each tenant, and give a tenant its own instance when it needs its own region or policies.

Start free on Earth

Related posts

Our newsletter

Get tutorials, AI agent recipes, webinars, and early product updates in your inbox every two weeks