Architecture
6 min read
November 22, 2026
How to design a scalable SaaS architecture
A practical SaaS architecture blueprint: modular monolith first, tenancy and isolation, roles and permissions, data growth, background jobs, billing as a state machine and observability from day one.
By Parth Patel
Most SaaS products don't fail because the architecture can't scale to a million users. They fail because the architecture makes the next ten features slow to build, or because one customer's bad day takes everyone else down with it. A scalable SaaS architecture is less about exotic infrastructure and more about a handful of decisions made early and made deliberately.
This guide walks through those decisions in the order they usually come up: tenancy, identity, the core application, data, background work, billing, and operations.
Start with a modular monolith
The first instinct on a new SaaS product is often microservices. For most teams it is the wrong first step. Microservices add network calls, distributed failures, separate deployments and a lot of operational work before you know where your real boundaries are.
A modular monolith gives you most of the benefits with a fraction of the cost:
- One deployable, so releases, local development and debugging stay simple.
- Strict internal modules (billing, accounts, projects, notifications) that talk to each other only through explicit interfaces, never by reaching into each other's tables.
- A clear path out. When a module genuinely needs to scale or deploy separately, its boundary already exists.
The rule that makes this work: each module owns its data. If the reporting module needs order data, it calls the orders module or consumes its events. It does not join across tables it doesn't own.
Decide the tenancy model on day one
Tenancy is the decision that is most expensive to change later. There are three common models:
| Model | Isolation | Cost per tenant | Operational effort |
|---|---|---|---|
Shared tables with a tenant_id column | Logical | Lowest | Lowest |
| Schema per tenant | Stronger | Medium | Medium (migrations per schema) |
| Database per tenant | Strongest | Highest | Highest |
Most B2B SaaS products start with shared tables and add stronger isolation only for the customers who pay for it. Whatever you choose, enforce it in one place, not in every query. In PostgreSQL, row-level security does this well:
ALTER TABLE projects ENABLE ROW LEVEL SECURITY;
CREATE POLICY tenant_isolation ON projects
USING (tenant_id = current_setting('app.tenant_id')::uuid);The application sets app.tenant_id at the start of each request, and the database refuses to return another tenant's rows even if a query forgets its filter. The multi-tenant architecture guide goes deeper on the trade-offs.
Identity, roles and permissions
Authentication answers "who are you"; authorization answers "what may you do, in which tenant". SaaS products need both, and the second is where most of the complexity lives.
A pattern that holds up well:
- Users belong to tenants through memberships, so one person can be in several organizations with different roles.
- Roles map to permissions, and code checks permissions (
projects:write), never role names. Adding a role then never requires a code change. - Enterprise customers will ask for single sign-on (SAML or OIDC) and SCIM provisioning. Use an identity provider or a library that supports them rather than building your own.
Every permission check should also be an audit event. When a customer's security team asks "who exported this data", you want the answer in seconds.
Design the data layer for growth
A single well-tuned PostgreSQL instance carries most SaaS products much further than people expect. Scaling problems usually start with a few predictable mistakes:
- Missing composite indexes that start with
tenant_id. Almost every query filters by tenant first. - Unbounded queries that return every row a tenant has ever created. Paginate with keyset pagination from the start.
- Reporting on the primary. Move analytics to a read replica or a warehouse before heavy dashboards compete with transactions.
When you do need more read capacity, add read replicas and route read-only queries to them. Sharding is rarely the first answer; the PostgreSQL performance checklist covers what to try first.
Move slow work off the request path
Anything that takes more than a few hundred milliseconds, depends on a third party, or can be retried belongs in a background job: sending email, generating reports, calling webhooks, processing uploads.
A queue gives you retries, back-pressure and isolation. Two rules keep it reliable:
- Make every job idempotent. Jobs will run twice. A job that charges a card or sends an invoice must check whether it already did.
- Use a transactional outbox when a database change must trigger a message. Write the change and the outbound event in one transaction, and let a relay publish it. Otherwise a crash between the two leaves them out of sync.
Billing is a state machine, not a webhook handler
Subscription billing looks simple until plan changes, proration, failed payments, refunds and usage-based pricing arrive. Treat billing as its own module with an explicit state machine (trialing, active, past due, cancelled), and treat the payment provider's webhooks as inputs to that machine, not as the source of truth for what a customer can do.
Store entitlements (seats, limits, features) on your side and check them in your code. When a webhook is delayed or arrives twice, your product still behaves correctly.
Observability from the first release
You cannot scale what you cannot see. Before launch, put in place:
- Structured logs with tenant, user and request IDs on every line.
- Traces across the API, background jobs and external calls, so a slow request shows where the time went.
- A few metrics that users feel: error rate, p95 latency per endpoint, and queue depth.
- Per-tenant views, because "the app is slow" is usually "the app is slow for one large tenant".
Alert on symptoms customers notice, not on every metric that moves.
A reference shape
Put together, a typical early-stage SaaS architecture looks like this:
- A web app (Next.js or a single-page app) behind a CDN.
- An API (a modular monolith in Node.js or Python) behind a load balancer, running in containers.
- PostgreSQL as the system of record, with row-level security for tenant isolation.
- Redis for caching, rate limiting and short-lived state.
- A queue and workers for background jobs and webhooks.
- Object storage for files, served through signed URLs.
- Infrastructure as code, CI/CD, and observability wired in from the start.
On AWS, that maps onto a small set of managed services; the AWS architecture for SaaS article shows one way to lay it out.
The decisions that matter most
If you remember five things:
- Start as a modular monolith with modules that own their data.
- Choose the tenancy model deliberately and enforce it in one place.
- Check permissions, not roles, and audit them.
- Keep slow and retryable work in idempotent background jobs.
- Make the system observable per tenant before the first customer arrives.
None of these requires a large team or an expensive platform. They require deciding early, writing the decisions down, and sticking to them until the evidence says otherwise.