Architecture
Multi-Tenancy

Multi-Tenancy

HiveForge supports both shared multi-tenancy and hard isolation models.

Tenancy Models

Multi-Tenant (Default)

Single database with Row-Level Security (RLS) to isolate tenant data.

Pros:

  • Cost-effective
  • Easy to manage
  • Simple deployments
  • Cross-tenant analytics possible

Cons:

  • Shared resources
  • Risk of data leakage (mitigated by RLS)
  • Noisy neighbor issues

Use When:

  • Standard SaaS application
  • Cost is a concern
  • You trust RLS implementation
  • Tenants have similar usage patterns

Hard Isolation

Dedicated database per tenant.

Pros:

  • Complete data isolation
  • Independent scaling
  • Regulatory compliance
  • No noisy neighbor issues

Cons:

  • Higher costs
  • Complex management
  • More deployment overhead

Use When:

  • Enterprise customers
  • Regulatory requirements (HIPAA, SOC 2)
  • High-value tenants
  • Custom tenant configurations needed

Implementation

Multi-Tenant with RLS

All tenant data in one database, isolated by RLS policies:

-- Example RLS policy
CREATE POLICY "Tenant isolation"
  ON projects FOR ALL
  USING (
    organization_id IN (
      SELECT organization_id
      FROM organization_members
      WHERE user_id = auth.uid()
    )
  );

Every query automatically filtered by user's organizations.

Hard Isolation

Each tenant gets dedicated Supabase instance:

// Get tenant-specific database connection
function getTenantDB(organizationId: string) {
  const org = await getOrganization(organizationId)
 
  if (org.isolated_db_url) {
    // Use dedicated database
    return createClient(org.isolated_db_url, org.isolated_db_key)
  }
 
  // Use shared database
  return createClient(sharedDbUrl, sharedDbKey)
}

Configuration

Set in .env:

# Multi-tenant mode
HARD_ISOLATION_ENABLED=false
 
# Hard isolation mode
HARD_ISOLATION_ENABLED=true

Platform admins can enable per-tenant:

await updateOrganization(orgId, {
  hard_isolation: true,
  isolated_db_url: 'https://tenant-db.supabase.co',
  isolated_db_key: 'tenant-anon-key'
})

Best Practices

  1. Always use RLS: Even in multi-tenant mode
  2. Test isolation: Verify tenants can't access each other's data
  3. Monitor costs: Hard isolation is expensive
  4. Plan migrations: Moving between models is complex
  5. Document choice: Be clear about your tenancy model

Next Steps