multi-tenancy

Design multi-tenant data isolation and routing strategies for Postgres SaaS architectures.

7|Updated Mar 19, 2026
One-click install
npx skills add https://github.com/camilooscargbaptista/cto-toolkit --skill multi-tenancy-camilooscargbaptista
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: multi-tenancy
Source: https://github.com/camilooscargbaptista/cto-toolkit/tree/main/multi-tenancy
Command: npx skills add https://github.com/camilooscargbaptista/cto-toolkit --skill multi-tenancy-camilooscargbaptista

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Provides clear architecture patterns and practical guidance to design data isolation and tenant routing for multi-tenant SaaS systems, reducing risk of cross-tenant data leakage and operational complexity.

Core Features & Use Cases

  • Isolation Models: Compares row-level, schema-level, and database-level isolation with trade-offs for cost, scalability, and compliance.
  • Tenant Routing & Connection Management: Shows patterns to select and manage per-tenant connections and connection pooling strategies.
  • Safety & Migration Guidance: Recommends query scoping, indexing, migration practices, and testing strategies to prevent cross-tenant access and enable per-tenant backup/restore.
  • Use Case: Selecting the appropriate isolation model for a growing SaaS product that must balance cost, regulatory requirements, and operational complexity.

Quick Start

Provide the application's tenant identification source and current PostgreSQL/ORM stack and ask for a recommended isolation model with routing and migration checklist.

Frequently Asked Questions about multi-tenancy

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
What is the best way to isolate data in a multi-tenant SaaS application using PostgreSQL?

Multi-tenant data isolation in PostgreSQL is achieved by evaluating row-level, schema-level, and database-level models to balance cost, scalability, and compliance. This strategy ensures tenant-aware queries and indexed tenancy keys to prevent cross-tenant data leakage.

How do I implement tenant routing and connection pooling for a SaaS architecture?

Implement tenant routing by selecting and managing per-tenant connections alongside connection pooling strategies. This involves configuring your ORM to route database queries automatically based on tenant identification sources, ensuring strict data isolation across tenants.

When should I choose schema-level isolation over row-level isolation for my SaaS product?

Choose schema-level isolation over row-level isolation when your SaaS product requires stronger data separation and compliance-ready backup capabilities, at the cost of higher operational complexity. Row-level isolation is generally more cost-effective for smaller scale operations.

How do I manage schema migrations for multi-tenant databases without downtime?

Manage multi-tenant schema migrations by enforcing migration isolation and per-tenant execution plans. This ensures that schema updates apply safely across isolated tenant databases or schemas without causing cross-tenant access issues or global downtime.

Does TypeORM support per-tenant connections and tenant-aware queries natively?

TypeORM can support per-tenant connections and tenant-aware queries by implementing specific routing patterns and connection pooling strategies. You must configure the ORM to dynamically select connections based on your application's tenant identification source.

How do I prevent cross-tenant data leakage in a multi-tenant SaaS database?

Prevent cross-tenant data leakage by enforcing query scoping, indexing tenancy keys, and applying strict tenant routing. These safety measures ensure that all database operations remain strictly isolated within the correct tenant boundary.