Prompt
Can you help me choose infrastructure for a SaaS app that needs tenant isolation, usage-based billing, and SOC 2 readiness?
Latest observation
Yes. A good way to choose is to optimize for the three things you named:
- Tenant isolation
- Usage-based billing
- SOC 2 readiness
Below is a practical decision framework plus a few infrastructure patterns that work well for SaaS.
1) Start with the tenancy model
Option A: Shared app, shared DB, tenant key on every row
Best for: early-stage SaaS, many small tenants, fast iteration
Pros
- Lowest cost
- Simplest to operate
- Easy to scale initially
- Good fit for usage metering if you design it well
Cons
- Isolation depends heavily on application correctness
- Harder to offer strong per-tenant guarantees
- More careful SOC 2 controls needed around data access
How to make it safer
- Use
tenant_idon every table - Enforce row-level security where possible
- Separate encryption keys or key wrapping per tenant if needed
- Log every access path to tenant data
- Make all background jobs tenant-aware
Option B: Shared app, separate DB/schema per tenant
Best for: mid-market customers, stronger isolation needs
Pros
- Better tenant isolation
- Easier data export/delete per tenant
- Stronger story for security reviews
- Reduced blast radius
Cons
- More operational complexity
- Migrations become harder
- More expensive than shared DB
Good compromise
- Use one app cluster
- Isolate high-value tenants into separate schemas or databases
- Keep small tenants in a pooled model
Option C: Separate account/VPC/account per tenant
Best for: regulated customers, enterprise deals, strict isolation requirements
Pros
- Strongest isolation
- Easiest to explain in security reviews
- Can align with enterprise procurement requirements
Cons
- Operationally expensive
- More complex CI/CD and observability
- Can slow product velocity
Typical approach
- Use this only for top-tier tenants
- Automate provisioning heavily
2) Recommended default architecture for most SaaS
For many SaaS apps, the best starting point is:
- Application: containerized stateless services
- Data: shared database with tenant isolation at the app layer
- Secrets: managed secret store
- Auth: centralized identity provider
- Billing: separate billing/usage pipeline
- Logging: centralized audit logs
- Analytics/metering: append-only event store or stream
This gives you a good balance of:
- speed
- cost
- SOC 2 readiness
- ability to evolve to stronger isolation later
3) Billing architecture for usage-based pricing
For usage-based billing, avoid calculating charges directly from transactional tables. Use a dedicated metering path.
Recommended billing flow
- Product emits usage events
- Events land in an append-only log/queue/stream
- Metering service aggregates usage by tenant, plan, and time window
- Billing service applies pricing rules
- Invoices generated and reconciled
Important design points
- Events must include:
tenant_iduser_idor actorusage_type- quantity
- timestamp
- request ID / idempotency key
- Make the event pipeline idempotent
- Keep raw usage events immutable
- Keep pricing rules versioned
- Recompute charges if pricing changes retroactively
Tooling choices
- Stripe Billing is a common choice for subscription + usage billing
- For metering, use:
- database outbox pattern
- queue/stream like Kafka, SQS, Pub/Sub, or Kinesis
- warehouse or OLAP store for reporting if needed
4) SOC 2 readiness considerations
SOC 2 is more about controls and evidence than a specific cloud. Infrastructure should make these controls easier.
Core infrastructure choices that help
- Cloud-managed services over self-managed where possible
- IAM with least privilege
- Centralized logging and audit trails
- SSO/MFA for admin access
- Encryption at rest and in transit
- Secrets manager
- Backups and tested restore procedures
- Infrastructure as Code
- Change management via pull requests
- Vulnerability scanning
- Monitoring and alerting
- Incident response playbooks
What auditors usually care about
- Who can access production?
- How is access approved and revoked?
- Are changes reviewed?
- Are logs retained?
- Are backups encrypted and tested?
- Is customer data protected?
- How do you monitor incidents?
- Can you show evidence?
5) Suggested cloud stack
A very standard SOC 2-friendly stack:
Compute
- AWS ECS/Fargate, GCP Cloud Run, or Kubernetes if you truly need it
- For most teams, managed containers are easier than Kubernetes
Database
- Managed PostgreSQL
Great default for SaaS and billing data - Use:
- tenant_id
- read replicas if needed
- encryption
- automated backups
- point-in-time recovery
Queue / events
- AWS SQS/SNS, GCP Pub/Sub, or Kafka if volume is high
Secrets
- AWS Secrets Manager / GCP Secret Manager / HashiCorp Vault if necessary
Auth
- Auth0, Clerk, Cognito, or your own OIDC integration
Logging/monitoring
- Cloud-native logs + metrics + alerting
- Centralized audit logs in immutable storage if possible
Storage
- Object storage for documents, exports, evidence, backups
- Use per-tenant prefixing or bucket separation for sensitive use cases
6) Isolation controls you should implement regardless of model
Even with separate databases, you still want these:
- Tenant-aware authorization middleware
- Row-level permission checks
- Request scoping by tenant
- Per-tenant rate limits/quotas
- Per-tenant encryption strategy if needed
- Audit logging for admin actions
- Separate prod/staging/dev accounts or projects
- No shared credentials
- No direct DB access for app developers by default
- Break-glass access with logging
7) A practical phased approach
Phase 1: MVP
- Shared app
- Shared PostgreSQL
tenant_ideverywhere- Stripe for billing
- Event-based usage metering
- Managed cloud services
- SOC 2-conscious basics from day one
Phase 2: Growth
- Add row-level security or stronger authorization layer
- Move large tenants to isolated schemas/databases
- Introduce a warehouse for reporting and revenue analytics
- Formalize access controls and audit evidence
Phase 3: Enterprise
- Dedicated tenant deployments for select customers
- Customer-managed keys if needed
- Separate environments/accounts for sensitive tenants
- Stronger contract and compliance posture
8) My recommendation if you’re undecided
If you’re building a typical SaaS app and want the best balance of speed, cost, and compliance:
- Use a managed cloud platform
- Use PostgreSQL
- Start with a shared database and tenant_id-based isolation
- Build usage metering as a separate event pipeline
- Use Stripe for billing
- Implement strong IAM, audit logs, encryption, backups, and IaC for SOC 2
- Design so you can later move high-value tenants to isolated databases or accounts
This is usually the most practical and least risky starting point.
If you want, I can also give you:
- a reference architecture diagram in words,
- a comparison table of AWS vs GCP vs Azure for this use case, or
- a recommended stack based on your expected tenant count and usage volume.