Engineering 5 min read Updated
SaaS architecture for small B2B teams
In short
A small B2B SaaS rarely needs microservices, but it cannot cut corners on tenant isolation, server-side roles, idempotent billing state and clean onboarding.
A B2B SaaS built by a small team fails far more often from messy permissions, mixed-up customer data or brittle billing logic than from traffic load. You do not need distributed microservices to ship a dependable multi-tenant product. You need four clean architectural boundaries from day one: tenant isolation, role-based access, decoupled billing state and predictable onboarding.
Tenant isolation: keep customer data separated by design
In B2B software, users belong to an organisation (tenant), and one user may even belong to several workspaces. Every domain table—projects, invoices, exports, files—must belong unambiguously to one tenant. Three isolation models cover most products:
| Model | Operational overhead | Isolation strength | When it fits |
|---|---|---|---|
| Shared schema with tenant_id in queries | Lowest; one migration path and one backup | Depends on strict repository/query discipline | Small teams starting fast with strong automated tests |
| Shared schema with database Row-Level Security | Low; one schema plus per-connection tenant context | Enforced by database engine (e.g. PostgreSQL RLS) | Default choice for multi-tenant B2B on PostgreSQL |
| Separate schema or database per tenant | Higher; N migrations and connection pooling complexity | Physical/logical boundary per customer | Enterprise contracts requiring isolated backups or data residency |
Whichever model you choose, never trust a tenant_id sent in a query string or JSON body without checking on the server that the authenticated user is a member of that tenant and has permission for the action.
Roles, memberships and server-side checks
Following the OWASP Authorization Cheat Sheet, enforce least privilege and deny by default on every endpoint—not only in the user interface. Keep authentication (who the user is) separate from organisation membership (which tenant they are acting in and with what role):
- Start with three clear roles: Owner (billing, workspace deletion, transferring ownership), Admin (team invites, settings, integrations) and Member (daily operational work). Add granular permissions only when real customers need them.
- Scope every lookup by tenant: fetch records with WHERE id = ? AND tenant_id = ? (or via RLS) so guessing a numeric or UUID identifier cannot leak another company’s record (IDOR).
- Audit sensitive changes: log role changes, API key creation, billing edits and data exports with timestamp, actor ID and tenant ID.
Billing, webhooks and subscription states
Billing systems such as Stripe Billing model a subscription as a lifecycle (for example: trialing, active, past due, canceled, unpaid). Treat the payment provider as the billing system of record and keep a clean, minimal projection of entitlement in your own database:
- Decouple billing from domain records: attach the subscription to the organisation, not to the individual founder’s user account, so transferring ownership or changing seats never orphans data.
- Process billing events idempotently: webhook events can arrive late, out of order or more than once (see Idempotency). Verify signatures, store processed event IDs, and fetch the current subscription object when in doubt.
- Design the past-due state explicitly: do not lock a paying team out on the first failed card charge. Allow a defined grace period with an in-app banner, then downgrade to read-only export mode before hard suspension.
- Support invoicing details early: B2B buyers in the EU need company name, billing address and VAT ID on invoices from the first payment.
Onboarding, invites and clean exits
B2B onboarding breaks when a single user signs up twice instead of joining an existing workspace. Keep the workspace lifecycle explicit:
- Create the first organisation automatically during sign-up or make workspace creation a single-step form with sensible defaults.
- Issue team invitations via signed, single-use, expiring tokens tied to the invited email address, and invalidate older pending tokens when re-sent.
- Provide a self-serve data export (CSV/JSON) and clear workspace deletion flow—this lowers buyer hesitation and simplifies GDPR compliance.
What a small team should defer
Wait before building custom multi-region replication, split billing microservices or complex visual permission builders. A well-structured monolith with one relational database (see SQLite or MySQL for a small product), strong tenant-isolation tests, and two-factor authentication for admins (Two-factor authentication for admins) handles hundreds of B2B organisations cleanly.
PostgreSQL Row-Level Security does not automatically restrict table owners or superusers unless configured with FORCE ROW LEVEL SECURITY and a non-superuser application role. Test cross-tenant isolation in automated integration tests against real database permissions.
Planning a B2B SaaS architecture or untangling an existing multi-tenant codebase? Describe the product through our enquiry form.
Common questions
- Should a small B2B SaaS use one database or one database per customer?
- Most small B2B teams start with a shared database and mandatory tenant IDs enforced at the data-access layer or via database Row-Level Security. Separate schemas or databases make sense when strict regulatory isolation or single-tenant backups are required.
- How do you prevent cross-tenant data leaks in API endpoints?
- Derive the active tenant from the authenticated server session or verified membership rather than client-supplied IDs, check object ownership on every read and write, and enforce tenant filters centrally in queries or database policies.
- How should subscription billing interact with core product records?
- Keep billing states (such as trialing, active, past_due and canceled) decoupled from business tables, update them via verified, idempotent webhook handlers, and allow a clear grace or read-only period before blocking access.
Sources
- Authorization Cheat Sheet, OWASP Foundation. Accessed 24 November 2026
- Row Security Policies, PostgreSQL Documentation. Accessed 24 November 2026
- How subscriptions work, Stripe Docs. Accessed 24 November 2026
Further reading
-
SQLite or MySQL for a small product
Choose SQLite when one application on one host reads and writes the data and writers can take turns; choose MySQL when many machines or simultaneous writers share it.
-
Two-factor sign-in for admin accounts
Require a second factor for every admin account, prefer phishing-resistant methods, and keep recovery from becoming a way around MFA.
-
Charging once, not twice
Idempotency keys let the server recognise a repeated payment request and return the first result, so a retry never creates a second charge or order.
Have an idea that should exist? Or a working product that needs more customers, a new website or a complete rework? Bring us anything. Apply with your idea