01
Shared tables
Company A asks for its invoices.
Web, SaaS & Mobile · SaaS anatomy
A SaaS is one system serving many companies at once, each with its own people, permissions, plan and data. Use the product below as different people in different companies, and watch what the backend does with every click.
01 · The sandbox
Two companies on different plans, eight people with five roles. Sign in as anyone, then create, approve, delete, export, invite, upgrade or switch language. Try things your role or plan doesn't allow, and try to read the other company's data.
Sign in as
Toko MakmurFree
Nusa LogistikPro
Faktur
Warung Sari INV-1001
Rp 1.250.000 · disetujui
Kios Jaya INV-1002
Rp 480.000 · draf
Toko Baru INV-1003
Rp 2.100.000 · draf
Behind the scenes
GET /api/invoices
200 OKSession ✓
session verified: Budi, manager
{ "sub": "u2", "tenant": "makmur", "role": "manager", "plan": "free", "lang": "id" }Tenant ✓
tenant = makmur, taken from the session, never from the request
const tenantId = session.tenant // "makmur"
Permission ✓
manager has invoice.view
can("manager", "invoice.view") // trueDatabase ✓
3 invoices for Toko Makmur; other companies' rows never leave the database
SELECT * FROM invoices WHERE tenant_id = 'makmur' AND deleted_at IS NULL ORDER BY created DESC
Response ✓
200 OK
response body
3 invoices
Every button works for everyone on purpose: click one your role or plan doesn't allow and watch where it stops.
Fictional companies and invoices, simulated payments; everything runs and stays in this browser tab. The same rules a production SaaS enforces on the server are applied here in the same order.
02 · Roles & permissions
Roles bundle permissions; every request checks one. Pick a role to see what it can do.
| Permission | |||||
|---|---|---|---|---|---|
| See invoices invoice.view | ✓ | ✓ | ✓ | ✓ | ✓ |
| Create invoices invoice.create | ✓ | ✓ | ✓ | ✓ | – |
| Approve invoices invoice.approve | ✓ | ✓ | ✓ | – | – |
| Delete invoices invoice.delete | ✓ | ✓ | – | – | – |
| Export to CSV invoice.export | ✓ | ✓ | ✓ | – | – |
| See the team team.view | ✓ | ✓ | ✓ | ✓ | ✓ |
| Invite people team.invite | ✓ | ✓ | – | – | – |
| Read the audit log audit.view | ✓ | ✓ | ✓ | – | – |
| Change the plan billing.manage | ✓ | – | – | – | – |
This exact table drives the sandbox above. In production it lives in one place on the server, and every endpoint asks it before doing anything; the screen only hides buttons as a courtesy.
03 · Plans & limits
Plans are limits and feature flags read from one place. The sandbox enforced these on every click.
to start
Free
most teams
Pro
large companies
Enterprise
Limits are numbers in one config, not code scattered across the app: the sandbox checks usage against them on every write, and feature flags read the plan on every request. Upgrading changes the config row, so new limits apply on the very next click.
04 · Tenant isolation
The most important promise a SaaS makes: one customer never sees another's data. There are three common ways to keep it, each with its own cost.
01
Company A asks for its invoices.
02
The app switches to the tenant's own schema in the same database.
03
The app looks up which database belongs to the tenant.
| Shared tables | Schema per tenant | Database per tenant | |
|---|---|---|---|
| Isolation | good, if no query forgets the filter | better: separate tables | strongest |
| Cost per tenant | lowest | medium | highest |
| Adding a tenant | insert one row | create a schema + migrate | provision a database |
| Reporting across tenants | easy: one query | harder: union across schemas | hardest: needs a warehouse |
| Typical for | most SaaS products | B2B with a few hundred customers | enterprise, banks, regulated data |
The sandbox uses shared tables: every query you saw ends in WHERE tenant_id = …, which is why “open another company's invoice” found nothing. Many products mix models, keeping most customers on shared tables and moving the largest to their own database.
05 · Unit economics
Recurring revenue only grows until churn catches up. Move the sliders to see where your ceiling is and whether each customer pays back what it cost to win.
MRR after 12 months
Rp 61.2m
MRR after 24 months
Rp 103.7m
ARR at month 24
Rp 1.24bn
Ceiling (MRR)
Rp 200.0m
where new customers = churned customers
Lifetime value
Rp 5.0m
a customer stays about 33.3 months
LTV : CAC
5.6 : 1
Payback
6 months
Your inputs, simple formulas: customers next month = customers × (1 − churn) + new; lifetime value = price ÷ churn; payback = CAC ÷ price. Revenue only, before costs, upgrades or discounts. A rule of thumb often quoted for healthy SaaS: LTV at least 3× CAC and payback within 12 months. Try halving churn: the ceiling doubles.