AI

Multi-Tenant SaaS Basics

By James KillickJanuary 1, 2025
Multi-Tenant SaaS Basics

TL;DR: Multi-tenant SaaS means one running instance of your app serves many customers at once, each with their own data kept separate. It is cheaper to run and easier to maintain than spinning up a separate copy per customer. Get the data model right early and the rest follows.

Multi-tenant SaaS means one app, many customers. Each customer, called a tenant, shares the same codebase and infrastructure but sees only their own data. Get this right and you cut your hosting bill, simplify deployments, and scale without rebuilding.

This guide covers what multi-tenancy actually means, how to structure your data, where things go wrong, and when you need dedicated infrastructure instead.

What does multi-tenant SaaS actually mean?

Imagine you build an invoicing app. Single-tenant means you spin up a separate server for every customer. That is expensive and slow to manage. Multi-tenant means one server, one database (or one schema per customer), many customers.

Your code runs once. All tenants use it. The app figures out which tenant is logged in and shows them only their records.

This is how Xero, Slack, and most modern SaaS tools work. It is the default model because it makes economic sense. You pay for one environment, not fifty.

For founders, it means you can go from ten customers to ten thousand without doubling your infrastructure cost each time.

How do you keep tenant data separate?

This is the most important question in multi-tenant SaaS. There are three common approaches.

Single database, shared tables. Every record has a `tenant_id` column. All customers share the same tables. Queries always filter by `tenant_id`. This is the simplest and cheapest option. The risk is a missed filter leaking one customer's data to another.

Single database, separate schemas. Each tenant gets their own schema (a namespace) inside the same database. Less risk of data bleed. Slightly more complex to manage migrations across hundreds of schemas.

Separate databases per tenant. Each customer gets their own database. Strongest isolation. Highest cost. Usually reserved for enterprise customers who require it for compliance reasons.

Most early-stage products start with shared tables and add row-level security (RLS) in the database to enforce isolation at the query level. Tools like Postgres RLS make this much safer than hand-rolled filters.

Start simple. Add isolation as your contracts and compliance needs demand it.

What is tenant context and why does it matter?

Every request your app receives needs to know which tenant it belongs to. This is tenant context.

You resolve context from the request itself. Common methods:

  • Subdomain (acme.yourapp.com identifies the tenant as "acme")
  • JWT claims (the token carries a `tenant_id` field)
  • API key lookup (the key maps to a tenant in your database)

Once you have the tenant ID, you attach it to every database query for that request. The cleanest way to do this is middleware that sets the context once and passes it through.

If you skip this and resolve tenant context ad hoc throughout your codebase, you will miss it somewhere. That is how data leaks happen.

For AI-powered SaaS products, tenant context also controls which models, prompts, or fine-tuned configurations a customer has access to. The same pattern applies.

When should you give a tenant their own infrastructure?

Most tenants never need it. But some will ask, and some will require it for legal reasons.

Common triggers:

  • Enterprise contracts that require data residency (data must stay in a specific country)
  • SOC 2 or ISO 27001 audits where shared infrastructure is a finding
  • Customers processing regulated data (health, finance, government)
  • Very high-volume customers who need dedicated compute to avoid noisy-neighbour problems

When this comes up, you have two options. Silo architecture gives that tenant their own stack entirely. Bridge architecture keeps shared infrastructure but routes that tenant to isolated compute for sensitive workloads.

NSW Government is a good example of where isolation requirements drive the architecture from the start. Building for compliance from day one is cheaper than retrofitting it later.

If you are building for founders and want a practical read on the whole AI app architecture question, the guide to building an AI application from a founder's perspective covers this in more depth.

What are the most common mistakes in multi-tenant builds?

Three mistakes come up repeatedly.

Missing tenant filters. A query that forgets to include `WHERE tenant_id = ?` will return records from every tenant. Row-level security at the database layer is the safest fix. Pair it with integration tests that specifically check cross-tenant isolation.

Shared cache without tenant keys. If you cache query results or API responses without including the tenant ID in the cache key, one tenant's data can appear in another tenant's session. Every cache key must include the tenant context.

Migrations that break existing tenants. When you add a required column or change a constraint, it affects every tenant at once. Use backwards-compatible migrations: add nullable columns first, backfill, then add the constraint. Never do breaking schema changes in a single deploy.

For AI features specifically, there is a fourth one: shared prompt context. If your AI pipeline caches conversation history or RAG embeddings without tenant isolation, you risk leaking context between customers. Tools like AILED are built with this kind of multi-tenant AI isolation in mind.

How do you handle billing across tenants?

Billing in multi-tenant SaaS ties to the tenant, not the user. A customer pays for their organisation's access, not each individual login.

The standard approach:

  • One Stripe customer per tenant
  • Subscription and usage data stored against `tenant_id`
  • Seat count or usage limits enforced at the tenant level
  • Webhooks from Stripe update the tenant's status in your database

Usage-based billing adds complexity. You need to meter events per tenant accurately. Tools like Stripe Meter or OpenMeter handle the aggregation. The key is tagging every usage event with the correct `tenant_id` at the point of capture.

For AI products, token consumption is often the usage metric. Track it per tenant from day one. Retrofitting usage metering after launch is painful.

If you are building an AI-first product and want a clear path from idea to production, talk to the team about our AI programs. We have built this infrastructure across 200+ apps since 2015 and can help you avoid the expensive mistakes.

How does onboarding work in a multi-tenant system?

Onboarding creates the tenant record and sets up everything that belongs to it. This is a critical flow to get right early.

A typical onboarding sequence:

  1. User signs up and creates an organisation (the tenant)
  2. System generates a unique `tenant_id` and creates the tenant record
  3. If using schema-per-tenant, the system provisions a new schema and runs migrations
  4. The founding user is assigned an admin role within that tenant
  5. An invite flow lets them add other users
  6. Billing is set up (often triggered by the first paid action)

Invite flows need to handle edge cases: what if the invitee already has an account in another tenant? What if they sign up with a different email? Map these out before you build.

For tech founders building their first platform, this is often where the architecture decisions made in week one start to bite. A clean tenant record schema and a well-structured onboarding flow make everything downstream easier.

FAQ

What is the difference between multi-tenant and single-tenant SaaS?

In single-tenant SaaS, each customer runs on their own separate instance of the app and database. In multi-tenant SaaS, all customers share one running instance, with data kept separate inside it. Multi-tenant is cheaper to operate and easier to update. Single-tenant is used when a customer has strict isolation or compliance requirements.

Is multi-tenant SaaS secure?

Yes, when built correctly. The key is enforcing tenant isolation at the database level, not just in application code. Row-level security in Postgres, for example, adds a hard enforcement layer that application bugs cannot bypass. The risk comes from missed filters or shared caches without tenant-keyed data. These are solvable problems, not fundamental flaws.

What database should I use for a multi-tenant SaaS app?

Postgres is the most common choice. It supports row-level security natively, handles schema-per-tenant setups well, and scales to serious workloads. For AI SaaS with vector search needs, Postgres extensions like pgvector keep your stack simple. The database choice matters less than getting the tenant isolation pattern right from the start.

When should I move a customer to dedicated infrastructure?

When they have a contract that requires it, a compliance audit that demands it, or a volume that creates noisy-neighbour problems for other tenants. Most customers never need it. Build for shared infrastructure first and add dedicated options as enterprise deals demand them. Trying to make every customer a silo from day one is expensive and slows you down.

How do I handle AI features in a multi-tenant SaaS?

Treat AI context the same way you treat data. Every prompt, every cached embedding, every conversation history must be tagged to a tenant and isolated. Do not share AI context across tenants. Usage metrics (tokens, API calls) need to be tracked per tenant from day one if you plan to charge for AI features. Build tenant context into your AI pipeline at the middleware layer, not as an afterthought.

Frequently asked questions

What is the difference between multi-tenant and single-tenant SaaS?

In single-tenant SaaS, each customer runs on their own separate instance of the app and database. In multi-tenant SaaS, all customers share one running instance, with data kept separate inside it. Multi-tenant is cheaper to operate and easier to update. Single-tenant is used when a customer has strict isolation or compliance requirements.

Is multi-tenant SaaS secure?

Yes, when built correctly. The key is enforcing tenant isolation at the database level, not just in application code. Row-level security in Postgres adds a hard enforcement layer that application bugs cannot bypass. The risk comes from missed filters or shared caches without tenant-keyed data. These are solvable problems, not fundamental flaws.

What database should I use for a multi-tenant SaaS app?

Postgres is the most common choice. It supports row-level security natively, handles schema-per-tenant setups well, and scales to serious workloads. For AI SaaS with vector search needs, Postgres extensions like pgvector keep your stack simple. The database choice matters less than getting the tenant isolation pattern right from the start.

When should I move a customer to dedicated infrastructure?

When they have a contract that requires it, a compliance audit that demands it, or a volume that creates noisy-neighbour problems for other tenants. Most customers never need it. Build for shared infrastructure first and add dedicated options as enterprise deals demand them. Trying to make every customer a silo from day one is expensive and slows you down.

How do I handle AI features in a multi-tenant SaaS?

Treat AI context the same way you treat data. Every prompt, every cached embedding, every conversation history must be tagged to a tenant and isolated. Do not share AI context across tenants. Usage metrics need to be tracked per tenant from day one if you plan to charge for AI features. Build tenant context into your AI pipeline at the middleware layer, not as an afterthought.

About James Killick

James is a co-founder of Devwiz and an AI product specialist. Since 2015 he has helped ship 200+ apps for founders, businesses and government, including work for NSW Government, Briometrix and Huskee. He builds AI-first platforms and writes about turning a proven program into software. He also hosts the Up in the AI podcast.

jameskillick.co · LinkedIn · AI Orchestrators

Tags: AI App Development