Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

Turso 7 min read How-to mediumAdept

Building AI Agent Databases: A Complete Guide to Database-per-Agent Architecture

Giving each AI agent its own SQLite-style database, instead of sharing tables keyed by tenant_id or using schema-per-tenant, makes isolation, debugging and cleanup trivial: deleting an agent is a single API call. Four patterns are shown on Turso: a cloud database per agent, embedded on-device databases, embedded databases synced to the cloud via push/pull, and hub-and-spoke with a shared coordination database, plus native F32_BLOB vectors with cosine-distance search for per-agent semantic memory. Per-request billing means idle or nearly idle agent databases cost little beyond storage. The main tradeoffs are cross-agent analytics, which need fan-out queries or a separate aggregate store, and the lack of ACID guarantees across agents, so the pattern suits many agents with independent state rather than a few with heavy cross-agent queries.

Related posts

  • 2 million databases and counting: the architecture behind Sauna's AI teammate

    Turso easyNovice

    Sauna, a proactive AI work assistant, gives every session, agent and connected inbox or calendar its own Turso database, creating about 90,000 databases a day and over 2 million in total. The team moved from Cloudflare Durable Objects to Containers with Litestream, which proved slow and expensive, and switched to Turso once per-database pricing was removed. Turso Sync keeps each database as a local file with two-way sync: on a conflicting pull it atomically rolls back to the last synced state, applies remote changes and replays local writes. The database-per-connection model simplifies isolation between users and lets storage outlive compute when changing hosting providers.

  • A database per agent: how Turso and Neon give different answers

    Turso easyNovice

    Neon and Turso both support a database per agent but differ in the unit: Neon gives each agent a Postgres project with its own autoscaling compute that suspends after 5 minutes idle and is billed by CU-hour, while Turso treats each SQLite-compatible database as a file managed by a shared server, billed by rows read/written and storage with unlimited databases on paid plans. For bursty agent workloads with many mostly idle databases, Turso avoids per-database compute clocks and adds per-database BYOK encryption, BYOC, on-device sync, and BEGIN CONCURRENT writes (about 9,500 TPS at 64 connections in 0.8). Neon remains better for branching a full production backend per agent, and Supabase Postgres is the recommended fit for Postgres-specific needs or storage-heavy, rarely queried data.

  • The Many-Database Architecture: Should You Give Every Tenant Their Own Database?

    Turso mediumAdept

    Shared schema with row-level security, schema per tenant, and database per tenant trade off isolation strength against operational cost. Shared schema stays simplest for many small tenants and cross-tenant analytics, but its isolation is only logical. Schema-per-tenant takes on most of the overhead of separate databases for only part of the isolation. Database-per-tenant gives structural isolation, trivial per-tenant deletion and placement in a chosen region. Cheap SQLite-based databases make it affordable, though routing, monitoring and cross-tenant analytics (via ETL or CDC) become operational work. A TypeScript example shows provisioning from a template database and scoping tokens per tenant.

  • Multi-tenancy at Scale: How to Give Every User Their Own Database

    Turso mediumAdept

    The standard warning against database-per-tenant assumes each database is a server process like PostgreSQL or MySQL, with its own memory, connection pool and backup schedule. When a database is a SQLite file, an idle tenant costs only storage, so 1,000 tenant databases fit in a ~$25/month Turso plan instead of five figures on RDS. Per-tenant databases replace Row-Level Security and `tenant_id` filtering with routing to the right database. That makes isolation, BYOK encryption, regional data residency and GDPR deletion architectural properties. The costs are harder cross-tenant analytics, coordinated schema migrations across the fleet, and a poor fit for consumer apps with millions of tiny users or products needing constant cross-tenant queries.

  • Analytics for Per-User Database Architecture

    Turso mediumAdept

    Aggregating analytics across a database-per-tenant SQLite architecture works with a simple daily ETL job: discover tenant databases via the Turso Platform API, run a per-database query for daily orders, revenue, active carts and new products, and upsert the results into a central metrics table keyed by date and database name. SQLite's ATTACH is noted as impractical beyond about 10 databases. The central table then supports cross-tenant reporting queries such as top stores by revenue and daily platform activity. Collection frequency trades freshness against load, so near-real-time dashboards require more frequent extraction.

The quest for software engineering knowledge.

Look:
Layout: