REFERENCE ARCHITECTURE · DIGITAL NATIVES & SAAS
Deliver secure dashboards and contextual insights inside digital products with tenant-aware ingestion, analytical serving and targeted caching. Avoid making primary transactional databases carry unlimited multi-user analytical workloads.
For SaaS engineering leaders · product platform teams · data platform engineers. Stack: ClickHouse · Redis · PostgreSQL · MongoDB Community Server (source-available, SSPL)
THE CHALLENGE
Customers expect dashboards and insights inside the product, not in a separate BI tool. As tenants, users and event volumes grow, analytical queries start competing with the transactional database that runs the product, cache strategies multiply, and a single missing tenant filter becomes a data-exposure incident. Embedded analytics needs its own serving design, with tenant boundaries, cost and latency measured from day one.
ARCHITECTURE OVERVIEW
Operational data and product events flow into an analytical store designed for tenant-aware queries. A single API layer owns authentication, authorization and tenant context, so dashboards never query data stores directly.
SaaS embedded analytics reference architecture where tenants query through an API layer to ClickHouse, with optional Redis caching and data ingested from PostgreSQL, MongoDB Community and product events.
Figure 1. Embedded Analytics for SaaS reference architecture (conceptual). Color key: see How to read our diagrams.
Conceptual pattern. Connectors, licensed capabilities, versions, security policies and topology are validated in a project-specific architecture.
Last reviewed: — · Version scope: —
COMPONENT ROLES
| Component | Classification | Role | Qualification |
|---|---|---|---|
| PostgreSQL | Independent OSS support | Transactional product data (system of record) | Analytical load moved off the primary; replicas or CDC used for extraction |
| YugabyteDB (optional alternative to PostgreSQL) | Independent OSS support | Transactional product data (system of record) where the product must accept writes in several zones or regions, or has outgrown one PostgreSQL primary | Chosen only after compatibility testing against YSQL; PostgreSQL remains the default where one primary meets scale and recovery objectives; extraction for analytics designed and tested per release |
| MongoDB Community Server (source-available, SSPL) | Independent community support | Document-based product data (system of record) | Change streams or batch extraction designed per collection |
| Event producers & pipelines (for example Apache Kafka) | Customer-owned or separately selected; Apache Kafka available with independent OSS support | Deliver product events and changes with tenant identifiers | Every record carries a validated tenant key |
| ClickHouse | Partner-led or ClickHouse OSS route | Analytical serving for usage, billing, campaign and customer insights | Tenant-aware schema, sorting keys and query controls are mandatory |
| Redis | Strategic partner | Bounded, invalidatable result cache and low-latency operational state | Used only where measurements justify it; tenant-scoped cache keys |
| API / BFF layer | Customer-owned | Authentication, authorization, rate limits, tenant context, parameterized queries | The only path from dashboards to data stores |
Links: ClickHouse partner · ClickHouse OSS · Redis · PostgreSQL · YugabyteDB · MongoDB Community · Apache Kafka
DESIGN TRADEOFFS
| Decision | Options | Choose based on | Validate with |
|---|---|---|---|
| Tenancy model | Shared tables with tenant key · Database per tenant · Dedicated cluster for large tenants | Number and size distribution of tenants, contractual isolation requirements, operational overhead | Isolation tests, per-tenant cost, operational load of schema changes |
| Tenant enforcement | Enforced in API only · API plus database-level row policies and per-tenant users or settings | Risk tolerance, defense-in-depth requirements | Automated cross-tenant access tests on every release |
| Data freshness | Streaming ingestion (for example Apache Kafka) · Micro-batch · Scheduled batch | What users expect to be live versus daily | Ingest-to-display lag measured per dashboard |
| Pre-aggregation | Raw events only · Materialized views / rollups for common query shapes | Query concurrency, dashboard shapes, storage budget | p95/p99 latency on known query shapes; storage growth |
| Result caching | No cache · Redis cache with TTL and event-based invalidation | Repeat-query rate, freshness tolerance, cost of recomputation | Hit rate, stale-result rate, latency with and without cache |
| Fairness controls | Global limits · Per-tenant quotas, rate limits and query complexity limits | Tenant size variance, noisy-neighbor risk | Load test with mixed large and small tenants |
| Operational database scale-out | Single PostgreSQL primary with replicas · YugabyteDB distributed SQL across zones or regions | Write growth, need to keep accepting writes through a zone failure, regional data placement, application compatibility, operating model | Compatibility test against YSQL; node and zone failure tests; write latency between regions measured in a PoC |
Choose the support route that fits: partner-led or independent ClickHouse OSS engineering.
SECURITY & RESILIENCE
Tenant context comes from the authenticated session, never from a client-supplied parameter. Apply defense in depth with database-level controls where supported.
Centralize sign-in, roles and per-tenant permissions in the API layer, integrated with your identity provider.
Parameterized, allow-listed query shapes only. No free-form SQL from the browser.
Encrypt traffic between services and data at rest where supported. Rotate service credentials through your secrets manager.
Define RPO/RTO for ingestion, the analytical store and the cache separately. Make ingestion replayable so data can be rebuilt after a failure.
Track per-tenant latency, errors, resource use and cost, and log data access with tenant identifiers for audit.
PROOF & OUTCOMES
Every engagement agrees acceptance tests with your team and runs them against representative tenants and query shapes.
| Acceptance category | Sample test |
|---|---|
| Tenant isolation | Cross-tenant access attempt never returns data outside tenant context |
| Concurrency | Test growing concurrent dashboards and known query shapes |
| Freshness | Measure ingest-to-display lag; distinguish live and cached data |
| Operational cost | Per-tenant storage/compute cost at representative retention |
| Resilience | Recover after ingest/serving component failure without silent data loss |
| Metric | How it is measured | Target |
|---|---|---|
| Concurrent tenants | Number of tenants and concurrent dashboard sessions sustained in a load test | Forecast peak plus agreed headroom |
| Chart latency | p95 / p99 chart query latency per tenant size band | Agreed in PoC acceptance criteria |
| Unit infrastructure cost | Storage and compute cost per tenant, or per active user, at representative retention | Assessed through workload and cost modeling |
| Isolation tests | Pass rate of automated cross-tenant tests in CI and production checks | 100% pass required for release |
| Fairness | Latency impact on small tenants while large tenants run heavy queries | Agreed tolerance |
Transactional databases are optimized for the product’s reads and writes. Heavy, many-user analytical queries compete with that workload and can slow the whole product. A dedicated analytical serving layer, fed by replicas, change data capture or event pipelines, protects the product and scales analytics separately.
Tenant context is derived from the authenticated session in the API layer, and every query is parameterized with it. Where the database supports it, row-level policies and per-tenant users or settings add defense in depth. Automated tests attempt cross-tenant access on every release.
No. Redis is added for bounded, invalidatable result caching or low-latency operational state when measurements show it helps. Many dashboards are served directly from the analytical store, especially with pre-aggregated views.
MongoDB Community Server is source-available under the Server Side Public License (SSPL), which is not an OSI-approved open-source license. Bassirah provides independent engineering support for it; this does not imply MongoDB endorsement or vendor support rights.
By measuring per-tenant storage and compute at representative retention, applying partitioning and retention policies, shaping common queries into pre-aggregations and setting per-tenant quotas. We build a cost model you can use for capacity planning and pricing decisions.
Bring your tenancy model, query shapes and growth plan. We will design the serving path, isolation controls and a cost model you can test.