Tenant isolation in multi-tenant SaaS: why tenant_id isn't enough
What we learned turning a single-Page bot into multi-tenant SaaS: tenant scoping at the database driver, leak tests with fault injection, webhooks and cron.
PagePilot
AI posts with an approval gate, Messenger replies grounded in each business's knowledge and guarded comment replies, for many businesses at once, with isolation enforced below the code.
Illustration. Product screens are not public yet.
PagePilot is a multi-tenant SaaS that lets businesses and agencies run many Facebook Pages with AI: daily posts behind an approval gate, Messenger replies grounded in each Page's own knowledge base, guarded replies to public comments, and subscription billing in Bangladeshi taka. It began as a conversion of an open-source, single-Page bot and is awaiting Meta App Review before launch.
A bot that serves one Page can't simply gain a tenant ID column. One Meta webhook delivers events for many Pages at once, global indexes and in-process caches can leak data between businesses, and scheduled jobs fire once per server replica.
Public comment replies raise the stakes further. Anyone can post text designed to manipulate an AI, and every reply goes out in the business's name.
Tenant scoping is enforced at the database driver, so code that forgets the tenant fails loudly instead of leaking data. A CI leak suite with fault injection proves the isolation on every change.
Webhook intake is signature-verified and durable: Meta always gets an answer within five seconds, while the work continues on a MongoDB job queue with leases and crash recovery. A per-tenant, timezone-aware scheduler publishes posts at the right local time, safe across daylight saving changes, and Page tokens are encrypted with AES-256-GCM.
Comment replies pass a four-layer prompt-injection guard and stay switched off until Meta approves them. Around that sit sign-in with 3 roles and 11 permissions, knowledge-base version history, usage quotas, data export and erasure, and taka billing through PipraPay with reminder emails.
The Next.js dashboard is built for business owners and agencies rather than marketing specialists: connect Pages, give each one the facts about the business, approve posts, and manage replies, team access and billing in one place.
Safety shapes the product as much as the interface does. Isolation, guards and encrypted credentials were designed in from the start, because a multi-tenant AI product only works if every business can trust it with its Page.
A pnpm and Turborepo monorepo of 4 apps and 9 packages on Node.js and MongoDB, with AI services on Gemini and eight key architecture decisions recorded with their trade-offs.
Signature-verified events acknowledged within five seconds and handed to a queue, so nothing is lost when a process restarts.
Isolation enforced at the database driver and verified by a CI leak suite with fault injection.
MongoDB-backed jobs with leases and crash recovery, and a per-tenant scheduler that is safe across daylight saving changes.
Gemini-written posts with an approval gate, retrieval-grounded Messenger replies and the four-layer comment guard.
Next.js with Better Auth, roles and permissions, encrypted Page tokens and taka subscriptions through PipraPay.
Phased so that each stage reduced risk and produced something usable.
Driver-level tenant scoping and the leak suite came before any feature work.
Webhook fan-in from many Pages, the job queue with leases and the timezone-aware scheduler.
Posts with an approval gate, retrieval-grounded replies and the four-layer guard for public comments.
Roles and permissions, taka billing, data export and erasure, and submission for Meta App Review.
What we learned turning a single-Page bot into multi-tenant SaaS: tenant scoping at the database driver, leak tests with fault injection, webhooks and cron.
What drives custom software development cost: scope, integrations, data, compliance and ongoing costs, plus pricing models and how to get a useful estimate.
PromptCV.app
Wedded Wonderland
PromptCV AI Sales Assistant
Tell us what you want to build and where you are today. We'll reply with questions, next steps and an honest view of how we can help.