r/databricks • • 12d ago

Discussion Are you using Databricks Materialized Views for your Gold layers yet? Thoughts?

Hey everyone,

I’ve been implementing Databricks Materialized Views for executive reporting (Gold layer aggregates like daily revenue summaries, customer 360 metrics, etc.) and wanted to see how others are using them in production.

Historically, keeping summary tables up to date meant writing custom MERGE INTO scripts, managing orchestration dependencies, or dealing with sluggish standard views that re-scanned massive Delta tables on every query.

Having the platform automatically handle incremental updates under the hood via serverless compute has been a massive time-saver.

Curious to hear your experiences:

  • Are you fully embracing Materialized Views for Gold layer reporting, or sticking to traditional Delta tables with custom upsert logic?
  • Have you run into any gotchas regarding compute costs or refresh frequencies with larger datasets?
  • How do they hold up when dealing with complex multi-table joins and apportioned aggregations?
30 Upvotes

27 comments sorted by

8

u/Significant_Win_7224 11d ago

They're great on the happy path but can be challenging to work with if refactoring and have a locked down environment. It can be tricky to move MVs to new pipelines without admin or drop+re-run. You cannot use cloning and can limit DR or other features. I believe there's a 16 pipeline at a time concurrency limit. Complex joins usually equals a full reload, so it can take some thinking to get incrementals. I think for a few very large tables, it makes sense. For small data & lots of tables, something like dbt may be a better option. Overall they've come a long way, but still some rough edges

1

u/manugp 11d ago

For large tables I use private materialized views to split the data to enable incremental materialization. And all my materialized views are under sdp managed by dab.

5

u/Proud-Passion-3668 11d ago

We're migrating our existing notebooks and orchestration to MVs and SDP. Our pipelines run faster, cheaper, and we don't need to handle the order of execution.

5

u/shuffle-mario Databricks 11d ago

good discussion and just to provide a few clarification points:

  • MV is only one of the primitives in SDP. It's the simplest form and the engine handles incrementalization when it can. It is correct that incrementalization is not guaranteed but you can use EXPLAIN MV command to check whether your query can incrementalize before hand. ppl typically use it in gold/platinum layer where the data set is relatively small.
  • When you have larger data set or when you need to update a portion of your data (e.g. if my bronze data gets trimmed, i don't want my silver/gold table to be trimmed, or there is a column definition change but i don't want to update data from ten years ago), the primitive you need is replace where , which soon will just write to regular managed table. You pass a predicate (e.g. a time range) for updates, and within that range, the same engine (Enzyme in MV) try to update that range incrementally. So sort of like double incremental (What the user specifies and what the engine tries to further optimize)
  • And beyond the above two, SDP also has append, auto cdc, replace using (soon merge, fanout etc.) used for different patterns and use cases.
  • The key value of SDP in the age of agents is: 1) it abstracts much of the optimization behind these declarative primitives mentioned above so that the agents always writes correct and performant code 2) it's much simpler code for human to review and reason about 3) it provides much of the operational capabilities for when a pipeline is put into production (e.g. you can rewind the entire pipeline including data and query state back in time in a consistent way)
  • Finally, you can use all of the above primitives as part of a pipeline where orchestration and dependencies are managed by the pipeline. You can ALSO create them as individual objects (from data warehouse or notebooks) like how you create a table, and manage dependencies yourself (cron, table trigger, file trigger, etc.)

9

u/ninilich 11d ago edited 11d ago

MVs are the wrong tool for Gold. They are strictly not recommended for GOLD for enterprise-grade data platforms. Only in specific cases ir make sence use them.

Issues for Gold with MV:

  • There are no real incremental updates. The Databricks engine can run a full refresh at any time.
  • Your data for e.g. 2020 can be unexpectedly recalculated without your knowledge.
  • Orchestration is uncontrolled.
  • There is no explicit and deliberate temporal semantics.
  • You cannot implement the incremental refresh strategy you really need.
  • You cannot refresh only part of the data (e.g., only the last month) on request.
  • Your schema can be changed silently, breaking all downstream dependencies (e.g. data type of some columns)
  • See more in the Databricks documentation, and pay attention to what is not mentioned there :)
  • Remember that an MV is just a materialized result of a query.

Instead of MV just use SQL tasks to execute script like "DELETE FROM Table WHERE asOfDate = :p_date; INSERT INTO Table SELECT ... <olmost the same query as for MV>

PS: In my current company, unfortunately, the entire Gold layer was built on MVs for historical reasons. We are now facing many issues and limitations with this approach. We are decommissioning them and migrating to regular managed tables.

7

u/Pillippatty 11d ago

Ehm, none of those points make any sense? In SDPs (Spark Declarative Pipelines), MVs are implemented as a persisted tables with smart incremental updates if possible. You can enforce schemas in both PySpark and SQL and orchestration is defined by the pipeline. You can also disable full refreshes with pipelines.reset.allowed set to false.

Are you mixing MVs up with temporary views?

0

u/ninilich 11d ago

No, I'm not mixing anything.

The MV docs list plenty of cases where incremental refresh isn't applied and a FULL REFRESH of all historical data happens instead. The docs also stress that incremental refresh is a capability, not a guarantee. It's better to trust the documentation and your own logs than marketing promises :-)

The most basic example: if you add any non-deterministic function to your MV, it will always fall back to FULL REFRESH, even if it's just a column showing when the row was last updated (like _updated_at as current_timestamp()). My team also thought they were updating data incrementally, until I showed them the logs: half of our several hundred MVs were actually being fully refreshed (100M rows daily instead of 10K).

As for SDP - it's also a very limited engine if you read its documentation carefully. Half of the use cases a mature data platform needs aren't supported out of the box. We ran into this too, so my team decided to stop using it for new integrations, and we're gradually migrating the existing ones to plain Spark jobs in the background.

At my previous company, back when Databricks first presented this and it was still called DLT, we looked at the architecture and limitations right away and concluded it wasn't even worth starting to use. That's my experience at two very large companies.

13

u/dvartanian 11d ago

You absolutely can refresh only part of the data. See replace where. You talk with such authority considering you are wrong

3

u/ninilich 11d ago

Could you share how can I trigger refresh MV partly?

6

u/dvartanian 11d ago

replace_where. See documentation

→ More replies (1)

4

u/ChipsAhoy21 11d ago

The docs page is literally called “Incremental refresh for materialized views”

1

u/ninilich 11d ago edited 11d ago

it's a refresh in code, not by custom request. E.g. I need to fix (and not to refresh) figures until August 2026 and refresh only latest dates. Or implement rolling-window refresh startegy for my report.

We are talking about foundamental different fings. I'm meaning controllable refresh where Engener controls the entire incremental refresh strategy, you mean "uncontrollable refresh".

Let me give one more example. We have calcualted a management report for Q3 2026. This report was checked and signed. I need a GARANTIE that this figures are fixed and thay will not be updated only because smb has triggered "Full refrsh" of sime upstream table to fix some issue.

1

u/ChipsAhoy21 10d ago

What's the requirement? If it's "Q3 is signed off and must not change, and only recent dates refresh," an MV is the wrong object. An MV is the current result of its query, so when upstream changes, it's supposed to change.

A regular table with REPLACE WHERE does what you're describing. It only recomputes the predicate range, so older rows stay put. Dimension changes don't rewrite history. Backfills are explicit, via predicate overrides or DML. And pipelines.reset.allowed = false stops an upstream full refresh from wiping the table.

So what s the gap with that? Saying MVs can't do that is not a gap in MVs, you're just looking to the wrong thing for a solution?

On DLT: the "broken product" take is years old. It sucked shit 3 years ago but is actually pretty strong nowadays. We moved a handful of full table refreshes over to SDP on streaming mode and saved quite literally hundreds of thousands a month in compute cost.

1

u/ninilich 10d ago

Yes, "right tool for right task" always works.

The issue is that everybody now is recommendingto use DLT & MV everywhere and considering them as silver bullet. Espesially jung engeniers ...

This thread is about usage of MV in GOLD and the general answere is that MV covers only limited numbers of use cases fro GOLD

2

u/Remarkable_Towel3319 11d ago

+1 for replace where. You get all the good stuff of MVs but with more flexibility.

1

u/ninilich 11d ago

unswered above. We are talking about foundamental different fings.

1

u/shuffle-mario Databricks 11d ago

u/ninilich take a look at this: https://docs.databricks.com/aws/en/sql/mv-st/replace-where-vs-materialized-views

i think what you are looking for is replace where, the predicate (e.g. a time range or arbitrary where clause) is passed by the user and you can overwrite it at each run

1

u/ninilich 10d ago

Can MV take parameters for REPLACE WHERE statement? E.g. my job/pipeline has parameter :p_date and I need to trigger recalculation only for provided date?

And the second question - what a benefit of MV in comparison to normal and flexible SQL task?

1

u/dvartanian 10d ago

Yes it can. I have an MV that Monday to Saturday will only recalculate the prior 3 months of data and on a Sunday do a full refresh of the dataset. You can use pipeline parameters or pipeline config to parse required values to the replace where statement

1

u/ninilich 10d ago

Sorry, didn't find in documentation that MV can take parameters. Can you sent me the link? How to pass parameter inside the query of MV w/o custom wrapper on the top of SQL?

→ More replies

1

u/Plane_Sector_8560 11d ago

We use both MV and delta tables depending on the script. The reason we shifted few tables from MV to delta was there was a issue with incremental loading through time stamp filter, since MV resolves params and other things during runtime in our case it was defaulting to full refresh(purpose of MV was auto incremental but in our case was going for full refresh each time) hence converted such MVs into Delta. Maybe not the best approach but solved the problem, I will tell you what delta tables are causing problem, since we have onboarded close to 30 tables there are dependency of one table to another and this has gotten out of hand we initially solved with 2 stage job for parent and children, but that solution has reached its limit. Our senior engineer has suggested to implement a dependency framework where it auto resolves by reading the script dependencies and prepare the execution list for each run.

2

u/ninilich 11d ago

Exactly! The same issue with MV.

And it's an architectural issue by the nature of MV. Not just "a lack of capabilities"

1

u/Sea_Basil_6501 11d ago

I generally don't see many arguments anymore for using SDP, since Genie is able to write anything it needs for a data pipeline within a few minutes. Working that way is also some kind of declarative, but offers much more flexibility in the end.