Multi-Tenant Directory Architecture: How to Run 10 Directories on One Server
Running separate deployments for each directory is expensive and unscalable. Here's how multi-tenant architecture lets you run unlimited branded directories from a single codebase.
The Problem with One-Directory-Per-Server
Imagine you launch a successful healthcare directory. Revenue is growing, so you decide to expand into home services. Then legal. Then automotive.
With a traditional deployment model, each directory means:
- A new server ($50-$200/month)
- A new database instance ($20-$100/month)
- A new deployment pipeline
- A new set of environment variables
- A new SSL certificate
- A new monitoring setup
By the time you’re running 10 directories, you have 10 servers, 10 databases, and 10x the operational complexity. Infrastructure costs alone eat $700-$3,000/month before you’ve generated a single lead.
The Multi-Tenant Alternative
Multi-tenant architecture runs all directories on one server, one database, one codebase. Each directory (tenant) shares the infrastructure but operates independently — its own domain, branding, listings, leads, and billing.
This is how AI Magic Directory works.
How Domain Routing Works
When a request hits the server, Next.js middleware inspects the Host header:
nutritionresponsetestingcenters.com→ Load NRTC directory configcaraccidentdoctors.us→ Load CAD directory configbestlocaldentists.com→ Load dental directory config
Each config defines the directory’s branding (colors, logo, hero text), SEO metadata, category tags, and settings. The same React components render differently based on the active directory context.
Traefik (the reverse proxy) handles TLS certificate provisioning for all domains automatically via Let’s Encrypt. Adding a new domain is a DNS change, not a deployment.
Data Isolation with Row-Level Security
The critical question in multi-tenancy is: “How do you prevent Directory A’s data from leaking into Directory B?”
AI Magic Directory uses PostgreSQL Row-Level Security (RLS) — policies that filter query results at the database engine level:
CREATE POLICY org_isolation ON listings
USING (org_id IN (SELECT id FROM orgs WHERE id = current_setting('app.current_org_id')::uuid));
This policy runs before results leave PostgreSQL. Even if the application code has a bug that forgets to filter by organization, RLS catches it. There is no code path that can bypass this — it’s enforced by the database engine itself.
The Cost Savings
| Model | 1 Directory | 5 Directories | 10 Directories |
|---|---|---|---|
| Separate deployments | $100/mo | $500/mo | $1,000/mo |
| Multi-tenant | $100/mo | $100/mo | $100/mo |
The marginal cost of adding a new directory is near zero. Same server, same database, same codebase. The only new resources are the directory configuration (a few database rows) and the DNS record.
Operational Simplicity
With one codebase:
- Updates: Deploy once, all directories get the update
- Monitoring: One dashboard, one set of alerts
- Backups: One database to back up
- Security: One attack surface to defend
- CI/CD: One pipeline to maintain
With separate deployments, every operational task multiplies by the number of directories. Multi-tenancy keeps it O(1).
When Multi-Tenant Makes Sense
Multi-tenant architecture is ideal when:
- You plan to run 2+ directories (most serious operators do)
- Directories share the same feature set (search, listings, leads, billing)
- You want to minimize infrastructure costs
- You need to launch new verticals quickly (minutes, not weeks)
It’s less ideal when:
- Each directory needs fundamentally different features (not just different branding)
- You need regulatory data separation (e.g., healthcare data in a specific jurisdiction that must be physically isolated)
For most directory operators, multi-tenancy is the clear winner.
Tags: