ivan_morozov11 Jul 2025 12:42

Planning a multi-tenant SaaS on Laravel. The main architectural decision is whether to use one DB with a tenant_id column on every table or separate databases per tenant.

Building for 50-500 tenants initially, potentially 10k+.

Replies (6)
alex_petrov11 Jul 2025 12:54

Single DB with tenant column: simpler, cheaper, easier to migrate schema across all tenants at once. Main risks: data leakage if you forget a where clause, noisy neighbor, harder to give tenants their data export.

0
dmitry_kv11 Jul 2025 13:30

Separate DB per tenant: stronger isolation, easy per-tenant backup and export, noisy neighbor problem gone. Main costs: running migrations across thousands of DBs is slow and complex. We use Tenancy for Laravel (stancl/tenancy) which handles this.

0
vova11 Jul 2025 15:03

At 50 tenants either works. At 10k+ tenants separate DBs become operationally heavy. Consider a hybrid: shared DB for small/trial tenants, dedicated DB for enterprise customers.

0
ivan_morozov11 Jul 2025 16:42

Global scopes on a Tenant model can enforce tenant_id filtering automatically in the single-DB approach. The risk is that global scopes can be bypassed with withoutGlobalScopes(). Requires discipline to not accidentally bypass.

0
sergey_web11 Jul 2025 17:09

Row-level security in PostgreSQL gives you the isolation of separate tables with the manageability of a single DB. Not available in MySQL/MariaDB. Worth considering if you have flexibility on DB choice.

0
katedev11 Jul 2025 17:26

We went single DB, 200 tenants. The global scope approach works but we had two data leakage incidents in two years where someone bypassed it for a query optimization. Now we have integration tests that verify tenant isolation for every endpoint.

0
Write a reply
Markdown. ```php blocks are runnable.