Veeva QMS data modeling

Niyojit
Databricks Partner

 

Hi everyone,

I’m currently working on a client project where the source data comes from Veeva QMS (Quality Management System). The data is being ingested into Databricks using Fivetran, and my next step is to build the data foundation, including the curated Gold layer and Materialized Views (MVs), which will serve as the data source for downstream dashboards.

Since QMS is a process-oriented system with multiple interdependent parent-child objects, I would appreciate the community’s guidance on a couple of design considerations:

1. Data Modelling Approach

Given that QMS contains several parent-child objects with dependencies between them, what would be the recommended approach for designing the Gold layer?

  • Should I model the data using a traditional fact and dimension approach?

  • How should I handle relationships and dependencies between different QMS objects?

  • Are there any recommended modelling patterns for process-oriented data?

2. Materialized Views and Historical Data

I'm also trying to understand the best approach for designing Materialized Views on top of the Gold layer.

  • Should MVs primarily represent the current state of the data?

  • If the business wants to analyse historical trends (e.g., how a QMS process or record has evolved over time), should I maintain historical data in the Gold tables and use those tables alongside the MVs?

  • Would you recommend maintaining separate current-state and historical views, or is there a better architectural approach?

I'd love to hear how others have approached similar QMS or process-oriented data modelling scenarios in Databricks, particularly when designing the Gold layer for both current-state reporting and historical analytics.

Any suggestions, best practices, or architectural recommendations would be greatly appreciated!

Thanks!

Niyojit

balajij8
Esteemed Contributor III

The challenge with process oriented systems are that each object (Deviation, CAPA etc) is a workflow whose value lies in its lifecycle and Fivetran usually replicates each object as a current state table (with _deleted soft-delete flag). You can use a hybrid dimensional model. In Silver, keep one normalized table per QMS object with all keys preserved and in Gold - build conformed dimensions (dim_quality_record covering all record types with record_type as an attribute along with dim_site, dim_product, dim_person, dim_date) so cross process KPIs join on shared keys. Model the process with two complementary facts like an accumulating snapshot fact (one row per record with milestone date columns like date_opened, date_investigation_closed, date_closed and derived days_open) that serves dashboards current state/cycle time queries and event fact (one row per state transition) that powers bottleneck analysis. Parent child dependencies like Deviation/CAPA/Action Item can stay in explicit foreign keys with a relationship table (record_id, parent_record_id, relationship_type). Avoid flattening the hierarchy into wide tables as Veeva's object model usually evolves and flattened structures can break due to it.

Materialized views refresh incrementally on a best effort basis and may fall back to a full recomputation when inputs change in ways the planner cannot handle and non deterministic expression such as current_date() or a rolling window inside its definition prevents incremental refresh entirely. You can store the history in Gold Delta tables (SCD Type 2 for slowly changing attributes in dim_quality_record and the event fact for full evolution). MVs can stay on top as current state and aggregate layers for dashboards. You can declare primary/foreign key constraints with RELY on the Gold tables to help the optimizer.

tajamulkhan
Esteemed Contributor

Hi Niyojit, I would start by defining what one row represents in each Gold table and which historical questions the dashboards must answer.

A practical design would be:

- Current process fact: one row per quality record, with its current status and milestone dates.
- Transition fact: one row per recorded status change, for time-in-stage and bottleneck analysis.
- Daily snapshot fact: one row per record per reporting date, if users need historical backlog or overdue counts.
- Shared dimensions: site, product, owner and date.
- Relationship tables where records have many-to-many relationships.

Keep child objects at their own grain. Joining several child tables directly to a parent can multiply rows and inflate dashboard measures. Aggregate each child to the required parent grain before joining.

For history, first confirm what Fivetran actually delivers. If it only captures the latest state between syncs, building SCD Type 2 downstream cannot recover intermediate transitions that were never ingested. Exact lifecycle analysis needs source audit or transition records.

Materialized views can serve both current and historical reporting. They materialize the result of a query, so history must exist in the underlying data. Refreshing an MV over a current-state table does not create historical snapshots.

For example, assuming you maintain a daily snapshot table with one row per record per day, this MV provides historical backlog by site:

CREATE MATERIALIZED VIEW gold.qms_daily_backlog AS
SELECT
snapshot_date,
site_id,
COUNT(*) AS open_records
FROM gold.qms_daily_snapshot
WHERE is_open = true
GROUP BY snapshot_date, site_id;

The table and column names above are illustrative. Define is_open using the business-approved lifecycle states.

One clarification on incremental refresh: current_date() does not always prevent it. Databricks supports time functions in a WHERE condition that can be applied directly to one input table. Using those functions in a SELECT list, join condition or aggregate forces a full recompute.

I would keep retained history in Delta tables and use MVs for dashboard queries over that history. That also allows a full MV refresh to reconstruct the historical report.

Official references:

https://docs.databricks.com/aws/en/ldp/incremental-refresh

https://docs.databricks.com/aws/en/sql/mv-st/materialized

https://fivetran.com/docs/connectors/applications/veeva-vault

Niyojit
Databricks Partner

Hi everyone,

Thanks for all the inputs!

Let me explain how I am currently approaching the data modelling and transformation for my Veeva QMS project in Databricks.

1. Bronze to Silver – Historical Data Tracking

Fivetran incrementally ingests data from Veeva into Databricks, which I land directly in the Bronze layer.

From Bronze to Silver, I am implementing SCD Type 2 using a hash-based change detection mechanism. I maintain the following columns to track historical changes:

  • effective_start_date

  • effective_end_date

  • is_current

This allows me to maintain historical versions of records while identifying the latest version using is_current = true.

2. Silver to Gold – Data Modelling

In the Gold layer, I am generating surrogate keys for each record while retaining historical versions.

Currently, I am keeping the source-level tables directly as Fact and Dimension tables rather than creating an entirely new dimensional model by combining multiple source objects.

3. Gold to Materialized Views – Current-State Reporting

On top of the Gold tables, I am creating Materialized Views (MVs) that contain only the current snapshot of the data using is_current = true.

I am maintaining one row per QMS record in each MV. For example:

  • One row per Deviation

  • One row per Investigation

  • One row per CAPA

  • And so on.

Within these MVs, I am joining the relevant dimension tables, such as dim_affiliate, dim_department, dim_organization, etc., to make the datasets more suitable for reporting.

4. Dashboard Layer – Databricks AI/BI

My plan is to use these MVs as the foundation for the AI/BI dashboard datasets.

I am thinking of joining the required MVs at the dashboard dataset level, performing the necessary aggregations, and defining the business KPIs directly within the AI/BI dashboards.

For historical reporting, I can leverage the Gold tables, which retain the SCD Type 2 historical records.

My questions to the community:

  1. Is this architecture aligned with recommended Databricks Lakehouse and dimensional modelling best practices, or would you recommend a different approach?

  2. Is it a good practice to keep source-level tables directly as Fact and Dimension tables in the Gold layer, or should I build separate business-oriented fact and dimension tables?

  3. Is maintaining separate current-state MVs for each QMS object (Deviation, Investigation, CAPA, etc.) a good approach?

  4. Would joining these MVs and defining aggregations/KPIs directly in AI/BI dashboard datasets be a good approach, or should I create another reporting/serving layer with pre-aggregated MVs?

  5. For historical reporting, would querying the SCD Type 2 Gold tables separately be sufficient, or should I design dedicated historical reporting MVs as well?

I would really appreciate feedback on this architecture, especially from those who have worked on complex, process-oriented data models or implemented Veeva QMS analytics using Databricks.

Looking forward to your suggestions and recommendations!

Thanks,
Niyojit

Niyojit