SaaS Architecture · August 31, 2026 · by Gaurav Singh Karki
Multi-Tenant SaaS with Next.js and Prisma: Architecture Lessons from Production
How to structure a multi-tenant SaaS with Next.js and Prisma — tenancy models, data isolation, per-tenant branding, encrypted credentials, and the mistakes to avoid, from a shipped compliance platform.
I built Captime, a multi-tenant SaaS for Hong Kong company-secretarial firms — client onboarding, KYC/AML, document generation, e-signatures, payments, and annual filings — multi-tenant from day one. Here's the architecture that held up in production, using Next.js 15, Prisma, and NextAuth.
Pick your tenancy model deliberately
- Shared database, tenantId column on every table: cheapest to run, easiest to migrate, right answer for 95% of B2B SaaS — this is what Captime uses
- Schema-per-tenant: stronger isolation, but migrations across hundreds of schemas become an operations project
- Database-per-tenant: only when contracts or regulators demand it; cost and tooling overhead are real
Enforce isolation in one place, not everywhere
The classic multi-tenant bug is one forgotten where-clause leaking another tenant's data. Don't rely on developers remembering: resolve the tenant once per request (from the session or subdomain), then run every query through a tenant-scoped data layer — a Prisma client extension that injects tenantId into every read and write. Code review then only has to catch raw-client usage, not every query.
Add a second line of defense in tests: a suite that creates two tenants, writes data as one, and asserts the other can never read it through any endpoint.
The details that make it feel enterprise-ready
- Per-tenant branding: logo, colors, and email templates stored per tenant and applied at render time
- Encrypted integration credentials: each tenant's third-party API keys encrypted at rest (AES-GCM), never in environment variables
- Event-driven background workflows (Inngest) keyed by tenant, so one tenant's heavy job can't starve others
- A 40+ field onboarding wizard that saves progress per step — enterprise clients never finish onboarding in one sitting
Mistakes I'd avoid next time
- Don't put tenant resolution in every page — do it in one layout/middleware layer
- Don't use auto-increment IDs across tenants; they leak volume information
- Don't defer the billing-per-tenant model; retrofitting seat or usage billing hurts
- Don't let uploads share one bucket without tenant prefixes and signed URLs
Building a multi-tenant product?
I've made these decisions before, in production. See my work or describe your product and I'll tell you honestly which tenancy model fits.
Building something like this?
I take on freelance projects worldwide — usually replying within a day.
Get in touchMore articles
How Much Does It Cost to Build a RAG Chatbot in 2026?
Real cost ranges for RAG chatbot development in 2026 — what drives the price, typical freelance rates, monthly running costs, and how to keep the budget under control.
Next.js + FastAPI RAG Architecture: What Actually Works in Production
A production-tested architecture for RAG chatbots using Next.js and FastAPI — ingestion, hybrid retrieval, streaming, evaluation, and deployment, from projects that shipped.
Stripe vs Razorpay vs Adyen for SaaS Billing: A Developer's Honest Comparison
Which payment gateway should your SaaS use in 2026? Stripe, Razorpay, and Adyen compared on subscriptions, global coverage, webhooks, and developer experience — by someone who has integrated all three.