|
| 1 | +--- |
| 2 | +title: 'Multi-Tenant AI Agents' |
| 3 | +sidebar_label: 'Multi-Tenant AI Agents' |
| 4 | +sidebar_position: 16 |
| 5 | +description: 'Deploy AI agents across many SaaS tenants with strict isolation and no per-tenant ETL pipelines.' |
| 6 | +pagination_prev: null |
| 7 | +pagination_next: null |
| 8 | +--- |
| 9 | + |
| 10 | +Spice serves as the data substrate for multi-tenant AI agents, giving each tenant real-time access to its own data sources with configurable isolation and no per-tenant ETL pipelines. A lightweight Rust runtime can be deployed once for all tenants, once per tenant, or in a hybrid topology, and every deployment exposes the same SQL, search, and AI inference APIs over HTTP, Arrow Flight, FlightSQL, ODBC, JDBC, and ADBC. |
| 11 | + |
| 12 | +```mermaid |
| 13 | +graph LR |
| 14 | + Agent[AI Agent or App] --> Router[Tenant Router] |
| 15 | + Router --> Dedicated1[Spice: Enterprise A] |
| 16 | + Router --> Dedicated2[Spice: Enterprise B] |
| 17 | + Router --> Shared[Spice: Shared Partitioned] |
| 18 | + Dedicated1 --> SourcesA[(Tenant A Sources)] |
| 19 | + Dedicated2 --> SourcesB[(Tenant B Sources)] |
| 20 | + Shared --> SourcesLT[(Long-Tail Tenant Sources)] |
| 21 | +``` |
| 22 | + |
| 23 | +Pipeline-per-integration architectures collapse at scale: every tenant brings its own schema, refresh cadence, and ownership, and ETL orchestration becomes the bottleneck. Spice federates queries across 30+ data sources and accelerates them locally, so adding a tenant is a Spicepod configuration change rather than a new pipeline. |
| 24 | + |
| 25 | +## Why Spice.ai? |
| 26 | + |
| 27 | +- **Zero-ETL federation**: Query PostgreSQL, Snowflake, Databricks, S3, Kafka, and 25+ other sources through a single SQL interface. Onboarding a tenant is a dataset declaration, not a pipeline build. |
| 28 | +- **Configurable isolation**: Choose logical, config-level, or runtime-level tenant boundaries. Isolation becomes a deployment property rather than something enforced in application code. |
| 29 | +- **Sandboxed runtimes**: The Spice runtime is lightweight enough to deploy one instance per tenant or per agent, giving each agent its own sources, acceleration layers, and secrets. |
| 30 | +- **Local acceleration with CDC**: Materialize tenant working sets into Arrow, DuckDB, SQLite, or PostgreSQL accelerators and keep them current with change data capture. |
| 31 | +- **Declarative configuration**: The [`spicepod.yaml`](../../../reference/spicepod) manifest defines datasets, models, secrets, and acceleration behavior, so tenant topology is version-controlled and auditable. |
| 32 | + |
| 33 | +## Deployment Patterns |
| 34 | + |
| 35 | +Four patterns trade off operational simplicity against isolation strength. Most SaaS workloads converge on a hybrid configuration. |
| 36 | + |
| 37 | +### Pattern 1: Query-Time Tenant Isolation |
| 38 | + |
| 39 | +One runtime serves many tenants. Datasets reference tenant-partitioned tables, and the application includes a tenant filter in every query. |
| 40 | + |
| 41 | +```yaml |
| 42 | +version: v1 |
| 43 | +kind: Spicepod |
| 44 | +name: saas-shared |
| 45 | + |
| 46 | +datasets: |
| 47 | + - from: postgres:public.events |
| 48 | + name: events |
| 49 | + params: |
| 50 | + pg_host: db.shared.internal |
| 51 | + pg_port: '5432' |
| 52 | + pg_db: app |
| 53 | + pg_user: ${secrets:PG_USER} |
| 54 | + pg_pass: ${secrets:PG_PASS} |
| 55 | + acceleration: |
| 56 | + enabled: true |
| 57 | + engine: arrow |
| 58 | + refresh_check_interval: 1s |
| 59 | +``` |
| 60 | +
|
| 61 | +This is the simplest and cheapest pattern to operate, but isolation is logical: correctness depends on every query path applying the tenant filter. |
| 62 | +
|
| 63 | +**View-based variant**: Move tenant filtering into the Spicepod using [views](../../../reference/spicepod/views), so agents query a tenant-specific view rather than constructing the filter at runtime. |
| 64 | +
|
| 65 | +```yaml |
| 66 | +datasets: |
| 67 | + - name: events |
| 68 | + from: postgres:public.events |
| 69 | + |
| 70 | +views: |
| 71 | + - name: view_tenant_abc |
| 72 | + sql: "select * from events where tenant='tenant_abc'" |
| 73 | + - name: view_tenant_xyz |
| 74 | + sql: "select * from events where tenant='tenant_xyz'" |
| 75 | +``` |
| 76 | +
|
| 77 | +### Pattern 2: Config-Level Tenant Isolation |
| 78 | +
|
| 79 | +One runtime, but each tenant gets its own dataset entry. The manifest is typically generated from tenant-onboarding metadata. |
| 80 | +
|
| 81 | +```yaml |
| 82 | +version: v1 |
| 83 | +kind: Spicepod |
| 84 | +name: saas-many-datasets |
| 85 | + |
| 86 | +datasets: |
| 87 | + - from: postgres:tenant_abc.events |
| 88 | + name: tenant_abc_events |
| 89 | + params: |
| 90 | + pg_host: db.pool.internal |
| 91 | + pg_db: app |
| 92 | + pg_user: ${secrets:PG_USER} |
| 93 | + pg_pass: ${secrets:PG_PASS} |
| 94 | + |
| 95 | + - from: postgres:tenant_xyz.events |
| 96 | + name: tenant_xyz_events |
| 97 | + params: |
| 98 | + pg_host: db.pool.internal |
| 99 | + pg_db: app |
| 100 | + pg_user: ${secrets:PG_USER} |
| 101 | + pg_pass: ${secrets:PG_PASS} |
| 102 | +``` |
| 103 | +
|
| 104 | +Tenant boundaries are explicit in configuration and easier to audit, but the manifest grows with tenant count and reload time and memory planning become operational concerns at large scale. |
| 105 | +
|
| 106 | +### Pattern 3: Runtime-Level Tenant Isolation |
| 107 | +
|
| 108 | +Run a dedicated Spicepod per tenant and route requests using tenant context from auth or session claims. Each runtime has an independent manifest, compute envelope, and cache. |
| 109 | +
|
| 110 | +```yaml |
| 111 | +version: v1 |
| 112 | +kind: Spicepod |
| 113 | +name: tenant-abc |
| 114 | + |
| 115 | +datasets: |
| 116 | + - from: postgres:public.events |
| 117 | + name: events |
| 118 | + params: |
| 119 | + pg_host: tenant-abc-db.internal |
| 120 | + pg_db: app |
| 121 | + pg_user: ${secrets:PG_USER} |
| 122 | + pg_pass: ${secrets:PG_PASS} |
| 123 | + acceleration: |
| 124 | + enabled: true |
| 125 | + engine: duckdb |
| 126 | + mode: file |
| 127 | + refresh_check_interval: 1s |
| 128 | + params: |
| 129 | + duckdb_file: /var/lib/spice/tenant-abc.db |
| 130 | +``` |
| 131 | +
|
| 132 | +This gives the clearest isolation model and per-tenant operational control, at the cost of higher operational overhead as tenant count grows. It fits regulated workloads that require strict data boundaries. |
| 133 | +
|
| 134 | +### Pattern 4: Hybrid Isolation |
| 135 | +
|
| 136 | +Large tenants run on dedicated Spicepods while the long tail shares a partitioned deployment. A tenant-aware router decides placement and clients query a single logical interface. |
| 137 | +
|
| 138 | +```yaml |
| 139 | +# router config (conceptual) |
| 140 | +tenants: |
| 141 | + - id: enterprise-abc |
| 142 | + spicepod: spicepod-tenant-abc |
| 143 | + - id: enterprise-xyz |
| 144 | + spicepod: spicepod-tenant-xyz |
| 145 | + |
| 146 | +default: |
| 147 | + spicepod: spicepod-shared |
| 148 | +``` |
| 149 | +
|
| 150 | +Hybrid isolation keeps the query interface stable while allowing tenant placement by policy, isolating high-load or regulated tenants on dedicated runtimes and using shared capacity for the long tail. It is the recommended starting point for variable SaaS workloads. |
| 151 | +
|
| 152 | +## Choosing a Pattern |
| 153 | +
|
| 154 | +The right shape depends on isolation requirements, tenant count, and query volume per tenant. |
| 155 | +
|
| 156 | +| Requirement | Recommended Pattern | |
| 157 | +| --- | --- | |
| 158 | +| Small tenant count, uniform workload | Pattern 1 or 1-view | |
| 159 | +| Explicit config-level boundaries, auditable manifest | Pattern 2 | |
| 160 | +| Regulated tenants, strict per-tenant SLOs | Pattern 3 | |
| 161 | +| Power-law tenant distribution | Pattern 4 (hybrid) | |
| 162 | +
|
| 163 | +## Benefits |
| 164 | +
|
| 165 | +- **Zero-ETL onboarding**: Add a tenant by declaring a dataset, not by building a pipeline. |
| 166 | +- **Deployment-level isolation**: Match isolation strength to business and compliance requirements without changing application code. |
| 167 | +- **Consistent interface**: Agents query SQL, search, and inference APIs the same way regardless of how tenants are partitioned underneath. |
| 168 | +
|
| 169 | +## Learn More |
| 170 | +
|
| 171 | +- [Multi-Tenancy for AI Agents without the Pipelines](https://spice.ai/blog/multi-tenancy-for-ai-agents-without-pipelines) — the engineering deep dive behind these patterns. |
| 172 | +- [Spicepod reference](../../../reference/spicepod) and [datasets reference](../../../reference/spicepod/datasets). |
| 173 | +- [Views](../../../reference/spicepod/views) for declarative tenant filtering. |
| 174 | +- [Data Acceleration](../../../features/data-acceleration) and [Change Data Capture](../../../features/data-acceleration/data-refresh). |
| 175 | +- [Federated SQL Query recipe](https://github.com/spiceai/cookbook/blob/trunk/federation/README.md). |
0 commit comments