MongoDB for SaaS
Every SaaS tenant wants custom fields, unique workflows, and their own data silo. MongoDB makes multi-tenancy a feature instead of a problem.
Variant Systems builds industry-specific software with the tools that fit the problem.
Why this combination
- The document model supports per-tenant schema variations. Each tenant's data carries custom fields and configurations without affecting other tenants or requiring migrations.
- Sharding by tenant ID provides horizontal scalability and data isolation as your customer base grows from hundreds to thousands of accounts.
- Aggregation pipelines compute usage metrics, billing summaries, and tenant health scores directly from operational data without a separate analytics layer.
- Change streams power real-time webhooks, activity feeds, and integration triggers that SaaS customers expect from modern platforms.
Multi-Tenancy That Scales With Your Customer Base
Every SaaS platform faces the multi-tenancy question. Shared database with tenant IDs? Database-per-tenant? Schema-per-tenant? Relational databases make each option painful at scale. MongoDB gives you a practical middle ground - shared collections with tenant-scoped documents, sharded by tenant ID for performance isolation.
Each tenant’s data lives in the same collections but carries tenant-specific custom fields, configurations, and workflow states. When your enterprise customer needs 15 custom fields on their contact records while your startup customer needs three, both coexist in the same collection without schema conflicts. Sharding by tenant ID ensures that large tenants generating heavy query loads do not degrade performance for smaller accounts. As your platform grows, you add shards to distribute the load rather than redesigning your data architecture. This approach scales from your first 10 tenants to your first 10,000 without fundamental changes.
Usage Metering and Billing Pipelines
Usage-based pricing requires accurate, real-time metering of every billable action. API calls, storage consumed, seats active, messages sent - each metric needs to be tracked per tenant, aggregated per billing period, and reconciled against plan limits. Getting this wrong means revenue leakage or angry customers.
You write usage events as documents with tenant ID, metric type, quantity, and timestamp. Aggregation pipelines roll these events up into billing period summaries - total API calls this month, peak storage usage, active seat count by day. Change streams trigger threshold alerts when tenants approach plan limits, enabling proactive upsell conversations or automated overage notifications. The same usage data feeds your internal analytics dashboards showing tenant health, engagement trends, and churn risk indicators.
Real-Time Webhooks and Integration Events
SaaS customers expect your platform to integrate with their existing tools. When a record changes, a workflow completes, or a threshold is crossed, external systems need to know. Polling-based integrations are fragile and wasteful. Event-driven webhooks are the modern standard.
Change streams make every document modification a deliverable event. Your webhook service subscribes to relevant collections, filters events by tenant and event type, and dispatches HTTP callbacks to registered endpoints. Each tenant configures their own webhook URLs and event subscriptions through documents in your configuration collection. Failed deliveries retry with exponential backoff, and delivery logs give tenants visibility into integration health.
Feature Flags and Progressive Rollouts
Shipping features to thousands of tenants simultaneously is risky. You need the ability to enable features per tenant, per plan tier, or as a gradual percentage rollout. Feature flags stored in MongoDB give you runtime control without code deployments.
Each tenant’s configuration document contains an embedded feature flags object mapping flag names to boolean or percentage values. Your application checks these flags on every request, reading from a cached configuration that refreshes via change streams when flags update. Product managers toggle features through your admin interface, the configuration document updates in MongoDB, the change stream propagates the update to application caches, and the feature activates within seconds. No deployment pipeline, no restart, no downtime.
Compliance considerations
Common patterns we build
- Tenant configuration documents with embedded feature flags, plan tier references, custom field definitions, and integration endpoint registrations.
- Usage metering documents with embedded event counts, resource consumption snapshots, and billing period boundaries per tenant.
- Activity feed documents with embedded event arrays, actor references, and target object metadata for in-app notification systems.
- Multi-tenant data partitioning using tenant ID prefixes on shard keys for balanced distribution and efficient tenant-scoped queries.