API Multi-tenancy Architecture

Design multi-tenant API architectures with tenant isolation, data segregation, and customization.

6/11/2026
Prompt
You are a SaaS architect specializing in multi-tenant systems and data isolation patterns.

## CONTEXT
I need to implement multi-tenancy in my API.

**Requirements:**
- Tenant Model: {{TENANT_MODEL}}
- Isolation Level: {{ISOLATION}}
- Customization Needs: {{CUSTOMIZATION}}
- Scale: {{SCALE}}

## TASK
Design multi-tenant API architecture:

### 1. TENANT IDENTIFICATION
**Subdomain:**
```
https://tenant1.api.example.com/users
```

**Header:**
```
X-Tenant-ID: tenant_123
```

**Path:**
```
/api/tenants/tenant_123/users
```

### 2. DATA ISOLATION STRATEGIES

**Shared Database, Shared Schema:**
- tenant_id column on all tables
- Row-level security

**Shared Database, Separate Schema:**
- Schema per tenant
- Connection pooling per schema

**Separate Database:**
- Complete isolation
- Connection management

### 3. MIDDLEWARE IMPLEMENTATION
```typescript
async function tenantMiddleware(req, res, next) {
  const tenantId = extractTenantId(req);
  const tenant = await getTenant(tenantId);

  if (!tenant) {
    return res.status(404).json({ error: 'Tenant not found' });
  }

  req.tenant = tenant;
  setTenantContext(tenantId);
  next();
}
```

### 4. CUSTOMIZATION
- Tenant-specific configuration
- Feature flags per tenant
- Custom branding/themes

### 5. RATE LIMITING
Per-tenant rate limits and quotas.

### 6. BILLING INTEGRATION
Usage tracking per tenant.

Or press ⌘C to copy

Variables (5)

Replace these placeholders with your own content before using the prompt.

[{TENANT_MODEL][{ISOLATION][{CUSTOMIZATION][{SCALE]{ const tenantId = extractTenantId(req); const tenant = await getTenant(tenantId); if (!tenant) { return res.status(404).json({ error: 'Tenant not found' }

Ready to use?

Copy and paste into your favorite AI tool

Test this prompt live

Try it in our AI Playground with Claude

Open Playground

Explore more Coding prompts

Browse Coding

Command Palette

Search for a command to run...