Most SaaS products do not fail because their architecture could not handle millions of users. They fail because they could not ship fast enough to find their first thousand. A good SaaS architecture is simple at the start and has clear paths to grow. This blueprint covers the decisions that are expensive to change later, and the ones you can safely defer.
Start simple
For the first version:
- One application, cleanly divided into modules: accounts, billing, core features, notifications.
- One relational database, usually PostgreSQL.
- Managed services for everything you do not need to differentiate on: hosting, email delivery, file storage, payments and error tracking.
This setup can comfortably serve a large number of customers and is far easier to change than a set of microservices.
Decide your multi-tenancy model early
Every SaaS serves many customers (tenants) from one system. How you separate their data is one of the hardest decisions to reverse:
- Shared tables with a tenant ID. Every row carries a
tenant_id. Simplest and cheapest to run. Isolation depends on every query filtering correctly, so enforce it centrally, for example with PostgreSQL row-level security. - Schema per tenant. Each customer gets their own set of tables in one database. Stronger separation, but migrations must run across every schema.
- Database per tenant. The strongest isolation, often required by large enterprise or regulated customers. The most expensive and complex to operate.
Most products start with shared tables and add a dedicated database option later for enterprise customers who need it.
Accounts, organisations and roles
Model organisations from day one, even if your first users are individuals. Businesses will want several users, invitations, roles (owner, admin, member) and the ability to remove people. Retrofitting organisations onto a single-user model is painful.
Plan for single sign-on (SAML or OpenID Connect) as an enterprise feature. You do not need to build it on day one, but keep authentication in one place so it can be added.
Billing and entitlements
- Use a subscription billing provider such as Stripe or Razorpay rather than building your own.
- Treat their webhooks as the source of truth for subscription status, and handle them idempotently: the same event may arrive more than once.
- Separate plans from entitlements. Your code should ask "can this organisation export reports?" rather than "is this organisation on the Pro plan?". That lets you change pricing without changing code.
- Plan for upgrades, downgrades, proration, failed payments and grace periods.
Caching
Add caching when measurements show a need, not before:
- A CDN for static assets and public pages.
- Redis for sessions, rate limits, short-lived tokens and frequently read data such as permissions.
- Cache with clear expiry times and invalidate on writes; stale permissions are a security problem, not just a display bug.
Background jobs
Anything slow or unreliable should not happen while the user waits: sending email, generating exports, processing uploads, calling third-party APIs and delivering webhooks to your customers.
Use a job queue such as BullMQ with Redis, or a managed queue like Amazon SQS. Give jobs retries with backoff, a dead-letter queue for repeated failures and dashboards to see what is stuck.
When data grows
- Index for your real queries, and review slow-query logs regularly.
- Add read replicas for heavy reporting.
- Partition very large tables, such as events or logs, by time.
- Archive old data that is rarely read.
- Move analytics to a separate data warehouse so reports do not slow the product down.
Reliability
- Automated backups, and tested restores. A backup you have never restored is a hope, not a plan.
- Monitoring of error rates, latency and queue depth, with alerts on what customers feel.
- Error tracking with enough context to reproduce issues.
- Staged rollouts and feature flags, so new features reach a few customers before everyone.
- A status page customers can check during incidents.
Security and compliance
- Encrypt data in transit and at rest.
- Keep audit logs of who did what, especially for admin actions.
- Apply least privilege to staff access and infrastructure.
- Expect enterprise customers to ask about security reviews and certifications such as SOC 2 or ISO 27001, and about where their data is stored.
- Follow the data protection laws where your customers are, such as India's DPDP Act and the EU's GDPR.
What to build when
First customers: modular monolith, shared-table tenancy with enforced isolation, organisations and roles, hosted billing, error tracking and backups.
Hundreds of customers: background job queue, caching for hot paths, read replicas for reporting, audit logs, feature flags and a status page.
Thousands of customers and enterprise deals: SSO, dedicated-database option, data warehouse, regional hosting, formal security certifications and, where teams or workloads demand it, extracting specific services.
Checklist
- Is tenant isolation enforced in one place, not left to each query?
- Are organisations and roles part of the data model?
- Does code check entitlements rather than plan names?
- Are billing webhooks idempotent?
- Does slow work run in background jobs with retries?
- Have you restored a backup recently?
Build the foundations that are hard to change, keep everything else simple, and let real usage tell you what to scale next.