---
title: "One isolated database per agent or customer"
description: "One isolated database per agent or customer keeps state separate, and SurrealDB Earth makes that affordable by billing usage, not idle servers."
url: https://surrealdb.com/blog/one-isolated-database-per-agent-or-customer
date: 2026-11-17
authors: "Tobie Morgan Hitchcock"
---

# One isolated database per agent or customer

![One isolated database per agent or customer](https://cdn.surrealdb.com/jfn44butwedmu657cqmx51pb.auto)

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](https://surrealdb.com/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.

## Why give every agent or customer its own database?

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.

## Why has this pattern been expensive?

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.

## How does Earth make it practical?

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.

## Instance or database: two levels of isolation

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](https://surrealdb.com/docs/learn/schema-management/multi-tenancy/namespace-and-database-architecture) keep their data apart.

The two levels suit different cases:

| | A database for each tenant | An instance for each tenant |
| :-- | :-- | :-- |
| Created | On the first request that names it | In Studio, with the CLI or with the Cloud API |
| Separate storage and commit log | No, shared within the instance | Yes |
| Separate data residency and network policy | No | Yes, such as EU data for one customer and US data for another |
| A transaction across several tenants | Possible, within one instance | Not possible |
| Number on Earth Free | Many in one instance | Up 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.

## How do you start with one database per agent?

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

```surql
-- 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;
```

```surql title="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:

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

## What does Earth cost?

Earth bills three meters: requests, storage and active hours. The [SurrealDB pricing page](https://surrealdb.com/pricing) always has the latest figures.

| | Free | Pro |
| :-- | :-- | :-- |
| Price | $0, with only an email address to sign up | $15 a month per account, at its launch price |
| Requests a month | 3M | 10M |
| Storage | 10 GB | 25 GB |
| Active hours a month | 100 | 1,000 |
| Earth instances | Up to 100 | Unlimited |
| At a limit | Pauses, and keeps your data | Keeps 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.

## What does a month look like in practice?

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.

| Meter | Used | Included in Pro | Billed |
| :-- | :-- | :-- | :-- |
| Requests | 9M | 10M | $0.00 |
| Storage | 20 GB | 25 GB | $0.00 |
| Active hours | 1,100 | 1,000 | 100 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.

## Summary

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](https://surrealdb.com/earth)
