Skip to content

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

Turso 4 min read How-to mediumAdept

How to Deploy Schema Changes to a Million Databases

Database-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.

Related posts

  • 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.

  • 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.

  • Database-per-User Architecture With Shared Application Environments: How and Why

    Neon mediumAdept

    A single shared application environment serving many per-customer Neon Postgres databases keeps deployment simple, but every tenant database must stay at the same schema version and data residency is hard to offer. Tenant identification can come from a login field, a per-customer subdomain, or a lookup from the user's credentials. A catalog database maps users or JWT-carried customer IDs to Neon project IDs for connection routing, and it also holds tier and feature-flag context. Schema changes need either slow, backward-compatible rollouts using views and triggers, or pre-upgrade testing of each tenant database on branches. The control plane should be kept separate from the app so failures don't take both down.

  • Skip the API, Ship Your Database

    Fly.io mediumAdept

    Instead of designing an API for internal services, Fly.io ships them a read-only SQLite replica via LiteFS, letting consumers query and join data with plain SQL. The pattern emerged from running Corrosion, Fly's gossip-based state store, on LiteFS, where a one-way replica avoided chatty gossip and needed only a small static-lease config. It moves query compute onto each client, which removes rate limiting and multi-tenant resource contention. The tradeoffs are that writes still need an API, the schema becomes a looser contract (mitigated with backward-compatible changes and views), and access control requires per-tenant databases.

  • Breaking up a monolith: How we’re unwinding a shared database at scale

    Datadog Engineering mediumAdept

    Datadog is splitting its large shared Postgres database into independently owned instances through a three-phase plan: logical separation into per-domain private schemas with explicit ACLs, access reduction so only owning teams query their tables directly, and physical separation onto managed OrgStore instances. Domain boundaries came from clustering Database Monitoring query samples and validating them with 30+ teams. Inter-domain foreign keys were replaced with CDC or Postgres replication. A homegrown PG Proxy lets teams migrate at their own pace and makes cutover a dynamic config change, with write downtime under five seconds and reverse replication kept for rollback. The platform investments that made this feasible, the Rapid service framework, OrgStore and PG Proxy, are presented as prerequisites, and each phase has concrete progress metrics.

The quest for software engineering knowledge.

Look:
Layout: