Million-Scale Isolated Databases: How AI Website Builder Infrastructure Handles the Load
This article explains how an AI coding agent can give each generated website its own database, and why serving a million such databases requires logical isolation, pooled resources, controlled schema changes, and automated lifecycle management.
When a user asks an AI agent in one natural-language sentence, “Build me a reading-notes website with login, search, and export features,” the agent can return a working URL within minutes. The frontend pages, backend APIs, account system, and standalone database are all ready. Data that a friend writes after signing up is stored reliably in the database for that site.
Compared with tools that only generate static pages, or that require users to debug code themselves, this capability takes over the full lifecycle, from development and deployment to database operations.
The smoother the experience, the harder the engineering problems behind it. Suppose one million users each make a similar request. The backend must then host one million isolated “production-grade databases” that real users read and write over long periods. If every logical database maps to a traditional cloud database instance, cost and operational complexity quickly become unmanageable. The real challenge is not whether a single database can be created. It is how to build million-scale tenant databases into sustainable infrastructure, balancing cost, scale, and performance, a trade-off often described as an impossible triangle.
1. Why the Traditional Instance Model Does Not Work
Traditional cloud databases usually treat an instance as the smallest unit for billing and management. Even the smallest instance has a fixed cost. Multiplied across a million users, the bill becomes unacceptable.
The load is also highly uneven. Many sites stay in a low-activity state for long periods after creation and may receive no writes for days or weeks. A small number of sites may see short bursts of traffic after their links are shared. If every tenant has a dedicated physical instance, idle resources cannot be reused, and peak capacity is hard to add on demand.
The second constraint is that the schema is generated on the fly by the model. Traditionally, table design required database administrators, reviews, and version control, which made schema decisions slow. In an agent-driven workflow, a user might ask, “What fields does a reading-notes app need?” or “Should the rating be stored as an integer or as text?” Such a question can trigger table creation, table changes, or index creation. The schema is no longer a stable precondition. It becomes a runtime input that keeps changing.
The third constraint is lifecycle automation. Tenants can create, modify, export, and delete their sites at any time. Their databases must follow those business states through initialization, migration, backup, recovery, and reclamation. Management methods centered on manual tickets cannot support a long tail of million-scale tenants.
2. The Core Approach: Logically Isolated, Physically Pooled
The practical path is not to start a separate physical database instance for each user. Instead, it provides database capabilities that are logically isolated but physically pooled. The control plane maintains the tenant directory, schema versions, quotas, and lifecycle states. The data plane uses shared resource pools to carry the actual storage and computation. Each tenant has its own namespace, its own permission boundary, and its own backup policy, while the underlying resources are scheduled, reused, and isolated as needed.
A schematic architecture can be summarized as follows:
Access layer -> Tenant routing/authentication -> Database proxy -> Resource pools (hot/warm/cold tenants)|-> Control plane: tenant metadata, schema versions, quotas, backups, audit|-> Storage layer: snapshots, logs, hot/cold tiering, encryption
A request first passes through the routing layer, which identifies the tenant ID. The proxy layer then handles connection reuse, rate limiting, and read/write routing. Active tenants are scheduled onto hot resource pools. Low-activity tenants move to sleep or warm pools. Their data stays in persistent storage and is woken on demand when accessed. This preserves the product experience of “one logical database per user” without the fixed cost of a million physical instances.
3. Dynamic Schemas Need Engineering Constraints
Letting a model generate a schema does not mean letting it execute arbitrary DDL directly. A safer approach is to place schema changes in a controlled pipeline. The model outputs a structured change intent. The system then performs syntax parsing, allowlist validation, dependency checks, and risk assessment, and generates an executable migration plan. High-risk operations, such as dropping columns, changing column types, or rebuilding large tables, should go through asynchronous jobs or manual approval.
Illustrative pseudocode:
plan = llm.generate_schema_change(user_intent, current_schema)validated = validate(plan, {allowed_ops: ["create_table", "add_column", "create_index"],require_backup: ["drop_column", "alter_type"],max_ops_per_txn: 5})if validated.risk == "high":enqueue_async_migration(plan, with_snapshot=True)else:apply_with_version(plan, tenant_id)
The system also needs to maintain a schema version table and a migration log to support staged rollout and rollback. Indexes should be driven by query patterns. Early on, only the necessary indexes should be created. Additional indexes can be added later based on slow-query reports and access logs, so that a model does not create many inefficient indexes at once and slow down writes.
4. Balancing Cost, Performance, and Isolation
Cost control depends on resource pooling and hot/cold tiering. Low-activity tenants do not need to keep compute resources running all the time. Storage can be tiered by access frequency, and backups and snapshots can be saved incrementally.
Performance depends on connection proxies, query rate limiting, tenant-level quotas, and slow-query governance. These measures prevent one tenant’s abnormal queries from overwhelming the shared pool. For isolation, the system needs strict binding of tenant IDs, row-level or namespace-level permissions, encryption key isolation, audit logs, and regular backup and recovery drills.
Observability must reach the tenant level. The system should record each tenant’s QPS, latency, error rate, storage growth, and migration status, and set error budgets and alerts. Only when a specific tenant can be identified can capacity planning and fault isolation work at million-tenant scale.
5. Practical Recommendations
First, change the product model from “database instance” to “tenant logical database.” Keep the user-facing experience of independence, and pool resources behind the scenes.
Second, build a schema change pipeline, and do not let the model execute irreversible DDL directly.
Third, schedule resources by activity level. Hot pools protect performance, and cold pools reduce cost.
Fourth, make all lifecycle operations asynchronous, traceable, and reversible.
Fifth, build the control plane and data plane on general-purpose cloud infrastructure by combining container platforms, object storage, log services, and monitoring and alerting. For example, on Baidu AI Cloud, you can select and combine general-purpose product categories. The architecture should still follow tenant isolation, elastic scheduling, and observability as its primary principles.
“One database per user” does not mean building a physical machine for every user. Logical isolation, resource pooling, and automated governance turn the experience of a million independent databases into a scalable engineering system. The real barrier is whether the control plane, data plane, schema governance, and cost model can work together.
