Meta webhook retries duplicate processing
Database idempotency keys per message id and composite keys for delivery status lifecycle events.
Case study
Multi-Tenant WhatsApp SaaS
wablast.in
Product preview
Architected WaBlast SaaS — a multi-tenant WhatsApp platform with NestJS and Fastify, Prisma and PostgreSQL, Redis and BullMQ, Meta Cloud API webhooks, Socket.IO realtime, a React Flow automation engine, Razorpay billing and entitlements, a Serwist PWA customer app, and Docker/nginx deployment on wablast.in.
Problem & goal
Indian SMBs need one workspace to run WhatsApp marketing, conversational automation, catalog commerce, and lead pipelines — without juggling separate tools, fragile webhook scripts, or custom Meta integrations.
WaBlast operates a subscription SaaS where tenants connect their WhatsApp Business lines, subscribe to product pillars — Marketing, Automation, Commerce, and Lead Management — and manage day-to-day operations from a customer PWA while platform operators govern plans, tenants, and Meta app configuration from a separate admin console.
Target users
Tenant owners and staff — campaigns, WhatsApp inbox, flow builder, orders, leads, and jobs from the customer app
End consumers — WhatsApp messages, catalog checkout, public lead forms, and job feedback links
Platform operators — plans, features, tenants, subscriptions, audit, and platform Meta settings from the admin console
Core capabilities
Secure login with Google OAuth, workspaces, role-based permissions, and team invitations across tenant and platform scopes.
Meta Cloud API adapter with multi-tenant webhooks and product-scoped phone line assignment per pillar.
Contacts, groups, templates, compose builder, paced campaign execution, and a WhatsApp one-to-one chat inbox.
Visual chat-flow builder with a runtime executor, PDF generation, webhooks, and payment branches.
Product catalog, orders, delivery zones, Meta catalog sync, and Razorpay checkout inside flows.
Multi-source lead ingest, CRM, jobs with line items and payments, PDF documents, and public feedback forms.
Razorpay subscriptions, GST invoices, and entitlement-driven feature gates with tenant overrides.
Live campaign progress, WhatsApp chat updates, and tenant events via a real-time gateway.
Dedicated console for plans, features, tenant lifecycle, and platform-level Meta app configuration.
High-level design
The platform ships as three deployable applications sharing one domain model: a Next.js customer PWA for marketing, automation, commerce, and lead management; a Next.js admin console for platform operations; and a NestJS API on a high-performance HTTP adapter handling versioned REST endpoints, Meta-compatible webhook ingress, and a real-time gateway. PostgreSQL stores tenant-centric relational data with Prisma. Redis powers BullMQ background job queues for webhooks, campaigns, and catalog sync.
External integrations include Meta Cloud API, Razorpay, Resend email, DigitalOcean Spaces for media, Firebase push, and Puppeteer for HTML-to-PDF generation. Inbound WhatsApp payloads are enqueued asynchronously with database idempotency before domain handlers run. Secure authentication with role-based access, encrypted integration credentials, webhook signature verification, and entitlement-driven feature gates protect tenant data and platform operations.
Production stack
Meta Cloud API layer
Per-tenant connections route outbound messages through a shared Cloud API client with product context for marketing, automation, commerce, or lead management.
Inbound payloads verified and enqueued to background workers with idempotency keys before fan-out to chat, flow executor, commerce, and lead handlers.
Template sync for campaigns and batch catalog sync for WhatsApp commerce with pacing and rate-limit backoff.
Tenants can assign distinct WhatsApp connections per product pillar when marketing, automation, commerce, and leads need separate phone lines.
Visual builder & runtime
React Flow graph editor stores node graphs as JSON with simulation preview before live sends.
Message, input, condition, calculation, list, form, webhook, Razorpay payment branch, commerce checkout, PDF, email, and delay nodes.
Per-conversation session tracking with variable interpolation and Handlebars PDF templates.
SQL and query nodes against tenant-connected databases with validated identifiers and safe preview queries.
Auto-provisioned checkout flow for new WhatsApp commerce connections so tenants can sell immediately.
Campaigns & catalog
Active campaigns chunk contacts by target groups, rotate templates, and send with configurable pacing, jitter, and rate-limit handling.
Conversations with notes, assignee, scheduled messages, and rich media compose backed by cloud object storage.
Import from CSV, spreadsheets, or live queries against connected data sources; organize into groups for targeting.
Variants, brands, categories, service charges, and delivery zones with Meta catalog batch sync.
Status templates, receipt and invoice PDF defaults, Meta utility templates, and Razorpay payment links on orders and in automation checkout.
Subscriptions & feature gates
Plans segmented by marketing, automation, commerce, and lead management with trial and addon quantity support.
Subscription orders with webhook signature verification and GST invoice PDF generation.
Multiple active subscriptions merge into additive feature caps enforced by entitlement-driven route guards.
Platform operators can override feature limits per tenant without changing base plan definitions.
Live updates
Real-time gateway broadcasts execution status and delivery counts as campaigns send.
New messages and read state pushed live to inbox views with tenant membership re-validation on subscribe.
Device token registration with foreground toasts and background delivery for chat and lead alerts.
Transactional email for invites, verification, and password reset via Resend.
Challenges solved
Database idempotency keys per message id and composite keys for delivery status lifecycle events.
Campaign processor with delay, jitter, consecutive rate-limit cap, and pause/resume on executions.
Product-scoped phone assignments so marketing, automation, commerce, and leads can use distinct connections.
Optional conversation lock with TTL to serialize automation per tenant and phone line.
Additive merge of numeric caps across active plans into a single entitlement view per tenant.
Serwist offline shell with Socket.IO campaign and chat hooks plus FCM fallback for background delivery.
Encrypted credentials at rest with safe preview queries and validated SQL identifiers for data source nodes.
Built for production load
BullMQ workers offload webhooks, campaigns, catalog sync, and scheduled WhatsApp messages
Campaign pacing and chunking respect Meta rate limits with configurable backoff
Redis-backed idempotency and optional conversation locks for dedupe
Stateless API scales horizontally behind nginx with shared JWT and Redis state
Prisma selective includes and pagination on tenant-scoped list endpoints
TanStack Query cache on customer and admin apps with targeted invalidation per product
Serwist PWA precaching for faster customer dashboard repeat loads
Operations
The production stack runs in Docker containers — database, cache, API, customer app, admin console, reverse proxy, and automated TLS — with scheduled database backups and health checks on core services. Asia/Kolkata timezone is applied across services. Structured log rotation keeps API disk usage bounded for ongoing operations.
Roadmap
Dedicated worker tier split from API process for large send volumes
Read replicas for analytics dashboards off hot OLTP workloads
WhatsApp Flows builder UI with deeper Meta Flow JSON parity
AI-assisted template and flow suggestions from campaign and chat analytics
Multi-region deployment for webhook latency and data residency
Advanced deliverability dashboard with template quality and opt-in tracking
Additional payment gateways beside Razorpay for international tenants