SaaS architecture ·
Six rules I never break in a multi-tenant SaaS
Step serves many real-estate offices from one database. The rules that keep each office’s data its own, and the money right, every single request.
By Kareem Mohamed, Web Developer at Digital House
Step is a multi-tenant SaaS workspace for Saudi real-estate offices: CRM, property management, owner balances, accounting. Every office shares the same servers and the same database. What keeps that safe is not a framework; it is a handful of rules applied everywhere.
1. The tenant comes from the token, only
The company_id is read from the signed login token and nowhere else: never from the body, the URL or a header. Every query carries it.
const [rows] = await db.query(
'SELECT * FROM leads WHERE company_id = ? AND id = ?',
[req.user.company_id, req.params.id]
);
2. Balances are queries, not columns
Collected, pending, overdue, commission: all computed with SQL aggregates on every request. There is no balance column to drift out of sync, and no cache to invalidate.
3. Late is a calendar test
A payment is overdue because its date has passed, not because a job flipped a status. Nothing has to run at midnight for the numbers to be right in the morning.
- 4. Migrations are idempotent: safe to run twice, guarded by existence checks.
- 5. Automatic rows (from invoices, contracts) have no edit or delete path at all.
- 6. Money is
DECIMAL, never floating point.
The best multi-tenant bug is the one the schema makes impossible to write.
- 1 Database
- ∞ Offices
- 0 Stored balances
If you are planning your own platform, building a SaaS MVP covers what the first version needs. Step itself started as a CRM and grew from there, as described in custom CRM development, and its numbers live in the kind of screens shown in business dashboard development.