← Back to All Analyses
Frontend & Next.js•9 min read•

Architecting a High-Concurrency Custom CRM with React, Next.js, Server Actions & PostgreSQL

How to engineer a sub-250ms multi-tenant CRM with React optimistic UI updates, Next.js App Router, PostgreSQL indexing, and automated multi-channel lead pipelines.

Pawan Pratap
Pawan PratapFounder & Lead Architect

1. Why Modern Businesses Are Ditching HubSpot and Salesforce

Enterprise SaaS licensing has reached absurd extremes. A 25-person sales organization using Salesforce or HubSpot easily burns $45,000 to $90,000 every year in per-seat subscription taxes. Worse, your team only uses 15% of the bloated features, while the software remains slow and disconnected from your core proprietary database.

At Dendrite Technologies, we build custom CRM and ERP platforms across the modern web stack (React, Next.js, Node.js, and PostgreSQL). By engineering a bespoke system, you eliminate monthly seat taxes, achieve sub-250ms search speeds, and own 100% of your source code and customer data.

2. PostgreSQL Multi-Tenant Schema & Indexing

A high-performance CRM demands a clean normalized schema with index-backed search across hundreds of thousands of customer profiles:

-- Core leads table with GIN full-text index
CREATE TABLE leads (
    id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
    company_id UUID NOT NULL REFERENCES companies(id) ON DELETE CASCADE,
    assigned_rep_id UUID REFERENCES users(id),
    name VARCHAR(255) NOT NULL,
    email VARCHAR(255),
    phone VARCHAR(50) NOT NULL,
    deal_value NUMERIC(12, 2) DEFAULT 0.00,
    stage VARCHAR(50) DEFAULT 'inquiry_received',
    search_vector TSVECTOR GENERATED ALWAYS AS (
        to_tsvector('english', coalesce(name, '') || ' ' || coalesce(phone, '') || ' ' || coalesce(email, ''))
    ) STORED,
    created_at TIMESTAMPTZ DEFAULT NOW(),
    updated_at TIMESTAMPTZ DEFAULT NOW()
);

CREATE INDEX idx_leads_search ON leads USING GIN(search_vector);
CREATE INDEX idx_leads_rep_stage ON leads (assigned_rep_id, stage);

3. Type-Safe Mutations with React & Next.js Server Actions

With Next.js App Router Server Actions, mutations avoid the boilerplate of separate API controllers. Permissions, validation (using Zod), and database transactions happen in one type-safe server boundary:

// app/actions/crm-actions.ts
'use server'

import { auth } from '@/lib/auth';
import { db } from '@/lib/db';
import { revalidateTag } from 'next/cache';
import { z } from 'zod';

const UpdateStageSchema = z.object({
  leadId: z.string().uuid(),
  newStage: z.enum(['new', 'contacted', 'proposal_sent', 'closed_won', 'closed_lost']),
});

export async function updateLeadStage(data: z.infer) {
  const session = await auth();
  if (!session) throw new Error('Unauthorized');

  const { leadId, newStage } = UpdateStageSchema.parse(data);

  await db.lead.update({
    where: { id: leadId, companyId: session.user.companyId },
    data: { stage: newStage, updatedAt: new Date() },
  });

  revalidateTag(`lead-pipeline-${session.user.companyId}`);
  return { success: true };
}

4. Optimistic UI for Lag-Free Deal Pipelines

Sales reps hate waiting for loading spinners while dragging deals across pipeline columns. By combining React 19's useOptimistic hook with Server Actions, the kanban card moves immediately on screen. If the background server network call fails, the UI gracefully rolls back with an alert toast.

5. Connecting WhatsApp Cloud API Webhooks

In regions like India, the Middle East, and Latin America, business is conducted over WhatsApp, not email. A modern full-stack CRM must ingest WhatsApp inquiries in real time. We connect webhooks directly to a Redis stream, extract customer intents, and display live conversation threads right inside the rep's CRM interface. For teams needing turnkey setup without developing a custom platform from scratch, we also provide our pre-configured WhatsApp Cloud API & CRM Setup for ₹500/Month.

6. Production Deployment & Zero-Seat Licensing

Deploying your custom CRM on AWS, GCP, or Oracle Cloud with Docker costs less than $40/month in server compute, regardless of whether you have 5 or 500 team members.

To explore building a tailored CRM and ERP solution for your organization, check out our Custom CRM & Full-Stack Platform Engineering or schedule a scoping call directly.

Building a Similar Architecture?

Discuss user flows, database models, and WhatsApp agent pipelines directly with Pawan Pratap. Zero middlemen.

Schedule Technical Scoping→