Overview
A SaaS architecture balances speed to launch with a clean path to multi-tenant scale. Start simple, isolate tenants early.
Layers
- Edge/CDN for static and cached responses.
- App servers (stateless) for business logic.
- Postgres with RLS for tenant isolation.
- Async workers for emails, exports and billing.
Diagram
Browser
│
▼
[ CDN / Edge ]
│
▼
[ App (stateless) ] ──▶ [ Postgres + RLS ]
│
└──▶ [ Queue ] ──▶ [ Worker ] ──▶ email / billing / export
Stateless app + isolated data.
Tenancy
isolation
create policy "tenant isolation" on invoices
for all
using (tenant_id = current_setting('app.tenant_id')::uuid);Billing
Use Stripe with webhooks to a durable event handler; reconcile invoices in a worker, not in the request path.
Scaling
Scale app servers horizontally, keep workers separate, and add read replicas before sharding.