Analytics for Per-User Database Architecture
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.
Related posts
- The Many-Database Architecture: Should You Give Every Tenant Their Own Database?
Turso mediumAdeptShared 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.
- Databases as Variables: What Unlimited Databases Actually Changes
Turso mediumAdeptTurso Cloud's paid plans no longer meter active databases, so a database costs only its storage while idle. That changes the cost math behind choosing a shared tenant_id schema. Because a Turso database is a file stored as 128 kB segments in object storage with copy-on-write branching, per-tenant, per-agent-session, per-experiment, per-regulated-user and per-PR databases become cheap, and provisioning takes two Platform API calls seeded from a template. Real costs remain: cross-tenant analytics pipelines (CDC helps), fleet-wide migration runners, routing and monitoring, so shared schemas still suit early, unregulated or analytics-heavy products, and a hybrid is often best.
- Multi-tenancy at Scale: How to Give Every User Their Own Database
Turso mediumAdeptThe 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.
- How to Deploy Schema Changes to a Million Databases
Turso mediumAdeptDatabase-per-tenant schema migrations can scale to millions of databases by inverting control: a hosted schema registry stores a versioned catalog of SQL scripts, and each client periodically reports its schema version, pulls the missing migrations and applies them locally. The registry needs only a simple migrations table, with no per-tenant state or distributed locks. Check-in timing (before critical operations, daily, or on user workflows) trades consistency against performance. The pull model suits offline-first apps that reconnect several versions behind, and a proof-of-concept is written in Go with SQLite.
- Building AI Agent Databases: A Complete Guide to Database-per-Agent Architecture
Turso mediumAdeptGiving 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.