Multi-Tenancy
How ProductFlo implements multi-tenant architecture
Multi-Tenancy Architecture
ProductFlo uses a sophisticated multi-tenant architecture that allows for secure data isolation between organizations while enabling cross-tenant collaboration when needed. This guide explains how the multi-tenancy system works and how to properly use it in your API integrations.
Schema-Based Isolation
ProductFlo implements schema-based tenant isolation at the database level. Each tenant (organization) gets its own PostgreSQL schema with dedicated tables.
This approach provides strong data isolation guarantees while still allowing for efficient resource sharing and cross-tenant operations when needed.
Tenant Context
All API requests operate within a tenant context, which determines which data is accessible.
Tenant Management
The following endpoints are available for managing tenants:
POST /tenant/create
Create a new tenant (organization)
GET /tenants
List all tenants the authenticated user has access to
GET /tenant/{tenant_id}
Get details about a specific tenant
PUT /tenant/{tenant_id}
Update tenant settings
Tenant Context Pattern
The API automatically resolves the tenant context using the following priority:
- X-Tenant-ID header (explicit tenant selection)
- Default tenant from user settings
- The first tenant the user has access to
Always explicitly set the tenant context when making API requests to avoid unintended cross-tenant data access.
Cross-Tenant Operations
Some operations can span multiple tenants when explicitly authorized. These operations use special endpoints with appropriate permission checks.
Tenant Data Model
Each tenant has the following structure:
Isolation Mechanisms
ProductFlo employs several mechanisms to ensure tenant isolation:
Database Isolation
- Each tenant gets a dedicated schema in PostgreSQL
- Schema names follow the pattern
tenant_<id>
- Cross-schema queries require explicit privileges
API Isolation
- Tenant context is required for all data operations
- Middleware validates tenant access permissions
- API responses only include data from the active tenant
File Storage Isolation
- Files are organized in tenant-specific directories
- Access control lists (ACLs) protect files at the storage level
- File URLs contain tenant-specific signatures for verification
Best Practices
When working with the multi-tenant API, follow these best practices:
-
Always specify tenant context: Include the
X-Tenant-ID
header in all requests. -
Validate tenant access: Check that users have appropriate permissions for the tenant they’re accessing.
-
Store tenant ID with data: When caching API responses, always associate them with the relevant tenant ID.
-
Handle tenant switching: Implement proper UI controls for users to switch between tenants they have access to.
-
Respect isolation boundaries: Don’t attempt to access data across tenants unless using explicit cross-tenant endpoints.
Security Considerations
The multi-tenant architecture includes several security features:
- Row-level security policies in the database
- Tenant validation middleware for all API requests
- Audit logging for cross-tenant operations
- Tenant-specific API rate limits
- Regular permission verification checks