Building a multi-tenant SaaS in Laravel: lessons from running 45+ companies on one codebase
I built Saleszawy, a sales, marketing and CRM platform used by 45+ companies, mostly on my own. Here is what I would tell anyone starting a multi-tenant Laravel app.
Pick the isolation model early. I use a separate database per tenant. It costs more to manage, but one company's data can never leak into another's, and you can back up, move or delete a single tenant cleanly. A shared database with a
tenant_idcolumn is simpler, but one missing scope in a query becomes a data leak.Resolve the tenant from the domain. Each company gets its own domain or subdomain. A middleware resolves the tenant on every request and switches the database connection before any controller runs.
Queues must be tenant-aware. Jobs carry the tenant ID and re-initialize the tenant before running. I run Laravel Horizon on Redis so I can watch queues per workload. The classic bug is a job that runs against the wrong database.
Real-time per tenant. WebSocket channels are namespaced by tenant, so a company only ever hears its own events.
Migrations are a release process. Every deploy migrates N databases. Run them in batches, log failures per tenant, and keep migrations backward compatible so one failed tenant does not block the rest.
Test the boundary. Write tests that create two tenants and assert that user A cannot read anything from tenant B.
Questions welcome, find me on LinkedIn.