CRM & SaaS development

Next.js SaaS Development: Architecture That Holds Up

An architecture guide for building SaaS on Next.js: when to split out an API, organization switching, plan-based feature locking, realtime, background jobs and deployment.

By Devang GandhiUpdated Nov 3, 20267 min read

Starting a SaaS on Next.js is easy. Keeping it pleasant to work on after two years, a few hundred customers and a dozen integrations is the real test. Most nextjs saas development guides stop at authentication and a pricing page. The decisions that actually hurt later are about tenancy, entitlements, background work and where long-running code lives.

I am a core engineer on Antoc AI, a real-estate CRM used by 100+ firms in India, and I have built several other SaaS products solo. This post lays out the architecture choices I now make by default, and why.

TL;DR

Use Next.js for the product UI and public pages. Put websockets, webhooks, cron and heavy jobs in a separate Node/Express service once the product needs them. Model organizations and memberships first, scope every query on the server, and centralize plan-based feature checks. Treat realtime, scheduled jobs and Sentry-style monitoring as day-one infrastructure.

key takeaways

  • Use Next.js for what it is great at, the product UI and marketing pages, and keep long-running work in a separate Node service when the product needs it.
  • Design the organization and membership model before the first feature, because every query will depend on it.
  • Plan-based feature locking belongs in one shared entitlement check used by both the API and the UI.
  • Realtime, scheduled jobs and error monitoring are core SaaS infrastructure, not extras to add after launch.

Where Next.js ends and the backend begins

Next.js can do a lot on its own: route handlers, server actions and server components that read data directly. For a small product, keeping everything in one app is a perfectly good choice. The Next.js App Router docs cover these primitives well.

The trouble starts when the product grows workloads that do not fit request-response:

Workload Fits inside Next.js? Why
Product UI, dashboards, settings Yes This is what it is built for
Public marketing and SEO pages Yes Server rendering and metadata
Simple CRUD for one client Yes Route handlers or server actions
Websocket connections Usually no Needs long-lived processes
Inbound webhooks at volume (ads, WhatsApp, payments) Often no Retries, queues and idempotency are easier in a service
Cron and drip campaigns No Needs a scheduler that is always running
Mobile apps sharing the same API Better separate One versioned API for all clients

A CRM hits every row of that table. So for products like Antoc, the Next.js app is the web client and a Node/Express service owns the API, Socket.IO and background jobs. For Client Mitra, a smaller product, I used the same split because the mobile apps needed the same API.

Organizations, memberships and switching

The single most important schema decision in B2B SaaS is how users relate to organizations. Get it wrong, and adding "invite a teammate" or "manage two businesses" later becomes a migration.

The model I use:

  1. User: identity only (name, email, phone, auth methods).
  2. Organization: the tenant, with plan, settings and billing.
  3. Membership: user plus organization plus role, with permissions.
  4. Session: carries the active organization ID.

Every API handler resolves the active membership first, then scopes queries by organizationId. No handler trusts an organization ID sent in the request body. Switching organizations just changes the active membership in the session and refetches data on the client.

Antoc supports multi-business organization switching this way: an owner running two agencies flips between them without logging out, and each business sees only its own leads, inventory and team.

Plan-based feature locking

Pricing tiers mean some features exist only on some plans. The naive approach scatters if (plan === "pro") checks through components. Within months, the UI hides a feature that the API still serves, or worse, the reverse.

Instead, define entitlements once:

const PLAN_FEATURES = {
  starter: ["leads", "pipeline"],
  growth:  ["leads", "pipeline", "whatsapp", "reports"],
  scale:   ["leads", "pipeline", "whatsapp", "reports", "voiceAgent", "mcp"],
};

The API exposes a can(org, feature) check used by middleware on protected routes, and the client receives the same entitlement list to render lock states and upgrade prompts. Limits like seats or monthly messages live in the same place. When sales invents a new plan, you edit one object.

Realtime, jobs and observability

Realtime. CRM users expect a new lead or WhatsApp reply to appear without refreshing. Socket.IO on the Node service, with rooms per organization, handles this. Emit events after the database write succeeds, and let clients refetch through their query cache rather than trusting payloads blindly.

Scheduled work. Reminders, nurture drips, report emails and sync jobs need a scheduler that is always running. On a VM, a PM2-managed worker process with cron-style schedules is simple and reliable. Make every job idempotent so a restart mid-run does not double-send.

Observability. Install error monitoring before launch. Sentry on both the Next.js client and the Node API shows you which customer hit which error, with the release that introduced it. Without it, you learn about bugs from angry WhatsApp messages.

Deployment that you understand

For Antoc, the services run on GCP VMs in asia-south1, close to Indian users, managed by PM2 behind Nginx. That setup is boring, cheap and easy to debug at 2 a.m. Managed platforms are great for a first version, but once you have websockets and workers, a VM or container host is often the more honest fit.

How I built this in practice

On the Antoc case study I describe the product I work on as a core engineer and top committer on the web client. The stack is Next.js and React on the front end, Node/Express with MongoDB and Mongoose behind it, Socket.IO for realtime, Sentry for errors, and GCP VMs with PM2 and Nginx.

The architecture above is what lets one codebase carry lead capture from Meta lead ads, Google Ads, portals, Sheets and webhooks, a WhatsApp flow builder with drips, an AI voice calling agent, a remote MCP server with OAuth, inventory with public share links, attendance and field team tools. Plan-based feature locking and multi-business organization switching sit in shared layers, so new modules inherit them instead of reimplementing them. Several of these, like webhooks and drips, would have been painful inside a request-response-only app.

Common mistakes

  • Putting websockets, cron and webhook processing inside serverless request handlers that time out or scale to zero.
  • Accepting an organization ID from the client instead of resolving it from the session on the server.
  • Scattering plan checks through components instead of one entitlement map shared by API and UI.
  • Emitting realtime events before the database write has committed.
  • Writing background jobs that are not idempotent, so a restart double-sends messages.
  • Launching without error monitoring and release tracking.

keep reading

FAQ

Is Next.js a good choice for SaaS development?+

Yes, for most B2B SaaS products. It gives you a fast React UI, routing, server rendering for public pages and a large hiring pool. Pair it with a dedicated backend when you need websockets, queues or heavy background work.

Should I use Next.js API routes or a separate backend?+

API routes and server actions are fine for simple CRUD and small products. Once you have websockets, long-running jobs, webhooks from many providers or multiple clients like mobile apps, a separate Node service is easier to scale and reason about.

How do you handle multiple organizations per user in a SaaS?+

Model users, organizations and memberships separately, store the active organization in the session, and scope every query by it on the server. An organization switcher then only changes the active membership.

Where should a Next.js SaaS be hosted?+

Managed platforms are quickest to start. For products with websockets, workers and predictable traffic, a VM with PM2 and Nginx or a container platform often costs less and gives more control.

Devang Gandhi

AI & full stack developer at Passdn, building CRMs, SaaS, AI agents and Flutter apps for clients in the US, UK, Australia, UAE and India. More about me

Read next

More in CRM & SaaS development