Skip to main content

Bassirah Technology

REFERENCE ARCHITECTURE · DIGITAL NATIVES & SAAS

Embedded Analytics Built for Tenants, Scale and Speed.

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

Fast, Secure Analytics for Products That Never Stop Growing.

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.

  • Production database under strain — Reporting queries on PostgreSQL or MongoDB slow down the core product for every customer.
  • Isolation by convention — Tenant filtering depends on every developer remembering a WHERE clause.
  • Noisy neighbors — A few large tenants or heavy dashboards degrade performance for everyone else.
  • Cost that grows faster than revenue — Storage and compute per tenant are unknown, so pricing and capacity planning are guesswork.
Illustration contrasting an overloaded product database with a separate analytics serving layer

ARCHITECTURE OVERVIEW

A Dedicated Serving Path for Customer-Facing Analytics

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.

On the right, users from three separate tenants view embedded dashboards inside the product. Their requests cross a trust boundary into an API or backend-for-frontend layer, which authenticates the user, authorizes the request, applies rate limits, derives tenant context from the session and builds parameterized queries (step 4). The API first checks an optional Redis result cache that uses tenant-scoped keys, expiry and invalidation and holds only results that are safe to discard (step 3). It then queries ClickHouse, the analytical serving layer, which stores tenant-keyed product usage, billing, campaign and customer-insight data with rollups and per-tenant quotas (step 2). On the left, the product application reads and writes its systems of record, PostgreSQL (or YugabyteDB, as an optional alternative where the product must accept writes in several zones or regions) and MongoDB Community Server, which is source-available under the SSPL. Change data capture, change streams or replicas and product event producers feed ingestion pipelines that validate tenant keys and load facts into ClickHouse (step 1). Crossed-out lines show that clients never access databases directly and that the primary databases are not used for heavy analytics. A band across the top shows observability collecting per-tenant p95 and p99 latency, fairness, cardinality growth and unit cost, and an automated test suite attempting cross-tenant access against the API (step 5). A bottom band lists controls: identity provider, secrets and encryption, audit logging, backup and replayable ingestion, and disaster recovery. Color coding marks Redis as a strategic partner platform, PostgreSQL and MongoDB Community as independently supported, ClickHouse as available through either route, and tenants, the API, the application, pipelines and observability as customer-owned.

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.

Logical Data and Query Flow

  1. Ingest tenant dataApplication events and operational data are ingested through governed pipelines from PostgreSQL (or YugabyteDB, where used), MongoDB Community or event producers, for example through Apache Kafka.
  2. Serve analyticsClickHouse acts as analytical serving layer for product usage, billing analytics, campaign or customer insight queries; tenant keys and query security are mandatory.
  3. Cache where justifiedRedis supports bounded, invalidatable result caching and low-latency operational state where justified by measurements.
  4. Enforce at the APIAPI/BFF layer handles authentication, authorization, rate limits, tenant isolation and secure parameterized query access.
  5. Observe and testObservability captures p95/p99 tenant query latency, resource fairness, cardinality growth and unit cost; automated tests detect cross-tenant access.

Conceptual pattern. Connectors, licensed capabilities, versions, security policies and topology are validated in a project-specific architecture.

Last reviewed: — · Version scope: —

COMPONENT ROLES

Who Does What in the Stack

Who Does What in the Stack
ComponentClassificationRoleQualification
PostgreSQLIndependent OSS supportTransactional product data (system of record)Analytical load moved off the primary; replicas or CDC used for extraction
YugabyteDB (optional alternative to PostgreSQL)Independent OSS supportTransactional product data (system of record) where the product must accept writes in several zones or regions, or has outgrown one PostgreSQL primaryChosen 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 supportDocument-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 supportDeliver product events and changes with tenant identifiersEvery record carries a validated tenant key
ClickHousePartner-led or ClickHouse OSS routeAnalytical serving for usage, billing, campaign and customer insightsTenant-aware schema, sorting keys and query controls are mandatory
RedisStrategic partnerBounded, invalidatable result cache and low-latency operational stateUsed only where measurements justify it; tenant-scoped cache keys
API / BFF layerCustomer-ownedAuthentication, authorization, rate limits, tenant context, parameterized queriesThe only path from dashboards to data stores

DESIGN TRADEOFFS

Decisions That Balance Isolation, Speed and Cost

Decisions That Balance Isolation, Speed and Cost
DecisionOptionsChoose based onValidate with
Tenancy modelShared tables with tenant key · Database per tenant · Dedicated cluster for large tenantsNumber and size distribution of tenants, contractual isolation requirements, operational overheadIsolation tests, per-tenant cost, operational load of schema changes
Tenant enforcementEnforced in API only · API plus database-level row policies and per-tenant users or settingsRisk tolerance, defense-in-depth requirementsAutomated cross-tenant access tests on every release
Data freshnessStreaming ingestion (for example Apache Kafka) · Micro-batch · Scheduled batchWhat users expect to be live versus dailyIngest-to-display lag measured per dashboard
Pre-aggregationRaw events only · Materialized views / rollups for common query shapesQuery concurrency, dashboard shapes, storage budgetp95/p99 latency on known query shapes; storage growth
Result cachingNo cache · Redis cache with TTL and event-based invalidationRepeat-query rate, freshness tolerance, cost of recomputationHit rate, stale-result rate, latency with and without cache
Fairness controlsGlobal limits · Per-tenant quotas, rate limits and query complexity limitsTenant size variance, noisy-neighbor riskLoad test with mixed large and small tenants
Operational database scale-outSingle PostgreSQL primary with replicas · YugabyteDB distributed SQL across zones or regionsWrite growth, need to keep accepting writes through a zone failure, regional data placement, application compatibility, operating modelCompatibility test against YSQL; node and zone failure tests; write latency between regions measured in a PoC
  • The primary transactional database is not an unlimited reporting engine.
  • Redis is not a durable substitute for PostgreSQL or MongoDB; cached results must be safe to discard.
  • Dashboards and embedded components never receive direct database credentials.

Running ClickHouse already?

Choose the support route that fits: partner-led or independent ClickHouse OSS engineering.

SECURITY & RESILIENCE

Tenant Isolation You Can Test

Tenant isolation

Tenant context comes from the authenticated session, never from a client-supplied parameter. Apply defense in depth with database-level controls where supported.

Authentication & authorization

Centralize sign-in, roles and per-tenant permissions in the API layer, integrated with your identity provider.

Safe query access

Parameterized, allow-listed query shapes only. No free-form SQL from the browser.

Encryption & secrets

Encrypt traffic between services and data at rest where supported. Rotate service credentials through your secrets manager.

Recovery without silent loss

Define RPO/RTO for ingestion, the analytical store and the cache separately. Make ingestion replayable so data can be rebuilt after a failure.

Observability & audit

Track per-tenant latency, errors, resource use and cost, and log data access with tenant identifiers for audit.

PROOF & OUTCOMES

Acceptance Tests Before Customers See a Chart

Every engagement agrees acceptance tests with your team and runs them against representative tenants and query shapes.

Acceptance Tests

Acceptance Tests
Acceptance categorySample test
Tenant isolationCross-tenant access attempt never returns data outside tenant context
ConcurrencyTest growing concurrent dashboards and known query shapes
FreshnessMeasure ingest-to-display lag; distinguish live and cached data
Operational costPer-tenant storage/compute cost at representative retention
ResilienceRecover after ingest/serving component failure without silent data loss

Measurement Plan

Measurement Plan
MetricHow it is measuredTarget
Concurrent tenantsNumber of tenants and concurrent dashboard sessions sustained in a load testForecast peak plus agreed headroom
Chart latencyp95 / p99 chart query latency per tenant size bandAgreed in PoC acceptance criteria
Unit infrastructure costStorage and compute cost per tenant, or per active user, at representative retentionAssessed through workload and cost modeling
Isolation testsPass rate of automated cross-tenant tests in CI and production checks100% pass required for release
FairnessLatency impact on small tenants while large tenants run heavy queriesAgreed tolerance

What You Receive

  • Tenant-aware data model and query design
  • Automated isolation test suite
  • Load-test and latency results for agreed query shapes
  • Per-tenant cost model
  • Runbooks for ingestion replay, scaling and recovery

Embedded Analytics for SaaS FAQs

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.

Book an Embedded Analytics Workshop.

Bring your tenancy model, query shapes and growth plan. We will design the serving path, isolation controls and a cost model you can test.