Materialized views (MVs) are a powerful feature in Azure Data Explorer (ADX) and Microsoft Fabric Eventhouse. They allow you to pre-aggregate large volumes of data, significantly reducing query execution time and improving performance.
However, creating a materialized view is only the first step. Ensuring that it continuously keeps up with incoming data, maintains acceptable freshness, and delivers consistent query performance requires careful design.
Over time, while working with customers on materialized view challenges, I've encountered several recurring issues and learned some practical lessons about designing and operating MVs successfully.
In this article, I'll explain how materialization works behind the scenes, discuss the factors that affect its performance, and share recommendations for building efficient and reliable materialized views.
- How Does Materialization Actually Work?
Before discussing best practices, it's important to understand what happens during materialization.
A materialized view is defined over a single source table and uses an aggregation query to summarize the incoming data.
As new data arrives, the materialization process incrementally updates the view rather than recalculating the aggregation over the entire source table.
At a high level, the process works as follows:
Step 1: Aggregate the new data
The materialization process takes the new data that has arrived since the previous materialization cycle and applies the aggregation query defined when the MV was created or altered.
This produces a set of aggregated rows representing the new data.
Step 2: Match the new aggregations with existing MV data
The newly aggregated rows are matched against existing rows in the materialized view using the grouping columns.
Conceptually, this operation resembles an inner join between the new aggregations and the existing materialized data.
The amount of existing data that must be examined is a critical factor affecting materialization performance.
Two mechanisms can reduce this scope:
- Lookback period: If a lookback period was specified when creating the MV, the matching operation is restricted to the relevant lookback window.
- Datetime grouping column: If one of the grouping columns is a datetime column, the materialization process can restrict the matching operation based on the oldest datetime value present in the newly aggregated data.
These optimizations can significantly reduce the amount of data involved in each materialization cycle.
Step 3: Update the materialized results
Once the matching operation is complete, two scenarios are possible.
Scenario A: A matching row already exists
When an existing row has the same grouping values as a newly aggregated row:
- The existing aggregation values are combined with the new aggregation values.
- The existing materialized row is deleted.
- A new row containing the updated aggregation values is added.
Scenario B: No matching row exists
If no existing row matches the grouping values, a new row containing the aggregations from the incoming data is added to the materialized view.
Why does this matter?
The key takeaway is that materialization performance depends not only on the volume of incoming data but also on the amount of existing materialized data that must be examined and updated.
A materialized view receiving relatively small amounts of new data can still experience significant materialization overhead if each cycle requires matching against a large volume of existing data.
Understanding this behavior is essential when designing the MV's grouping keys, lookback period, and partitioning strategy.
- How to Ensure Your MV Keeps Up with Incoming Data
One of the most common challenges customers encounter is materialization lag.
When data arrives faster than the materialization process can handle it, the gap between the source table and the materialized view grows.
Several design decisions can help prevent this situation.
Keep the MV Query Simple
Recommendation: Keep expensive transformations out of the materialized view definition whenever possible.
I recently encountered a customer scenario where the source table contained a large dynamic column. The MV query extracted numerous individual columns from this dynamic structure before performing the aggregation.
Although this approach was functionally correct, it introduced significant processing overhead into every materialization cycle.
A better approach is to perform these transformations earlier in the ingestion pipeline using an update policy.
The update policy can extract the required fields and store them in a structured table, allowing the MV to focus primarily on aggregation.
The same principle applies to joins.
If the aggregation requires joining data from multiple sources, consider performing the join through an update policy rather than repeatedly executing it during materialization.
This separates data preparation from aggregation and can reduce the complexity and cost of materialization.
The general principle is simple:
Do the expensive data preparation once during ingestion rather than repeatedly during materialization.
Of course, update policies also consume ingestion resources, so their performance and operational impact should be considered.
Choose the Right Lookback Period
The lookback period is one of the most important settings affecting materialization performance.
As explained earlier, the cost of each materialization cycle can depend heavily on the volume of existing data that must be matched against incoming aggregations.
A long lookback period increases the amount of data that may need to be examined, potentially making materialization more expensive.
A shorter lookback period can significantly reduce this cost.
However, choosing a lookback period that is too short introduces another risk.
Example: Choosing a lookback period
Suppose you know that data belonging to the same combination of grouping keys will never arrive more than seven days apart.
In this case, a lookback period of approximately seven days, with an appropriate safety buffer, may be sufficient.
There is little value in configuring a 30-day lookback period if the business and ingestion characteristics guarantee that all related data arrives within approximately seven days.
On the other hand, consider what happens when related data arrives outside the configured lookback window.
If the materialization process cannot find the existing aggregated row because it falls outside the lookback period, it may insert another row with the same grouping values.
Consequently, the materialized view may contain multiple rows for the same grouping combination.
This is an important correctness consideration, especially when querying only the materialized portion of the view.
Best practice: Choose a lookback period that closely reflects the maximum expected arrival-time difference between records sharing the same grouping keys, while allowing a reasonable safety margin.
Avoid unnecessarily large lookback periods, but never sacrifice aggregation correctness simply to improve materialization performance.
- Plan Large Backfills Carefully
Backfilling a materialized view with historical data can be one of the most resource-intensive operations in its lifecycle.
If the source table contains billions of records, creating an MV that processes the entire historical dataset may require substantial time and resources.
Before starting a large backfill, consider two questions.
Do You Really Need All the Historical Data?
Not every materialized view needs to aggregate data going back several years.
For example, if the primary purpose of the MV is to accelerate operational queries over recent data, processing several years of history may provide limited value.
Consider using the effectiveDateTime property to start materialization from a more recent point in time.
This can substantially reduce the initial workload and allow the MV to become operational sooner.
Consider Backfilling by Moving Extents
For very large datasets, another option is to prepare the aggregated historical data in a separate table and move its extents into the materialized view.
This approach can be particularly useful when dealing with billions of source records.
Instead of relying entirely on the regular materialization process to aggregate the historical data, you can prepare the required results separately and use the supported extent-movement mechanism.
For details, see the official documentation:
Create a materialized view: Backfill by moving extents
Best practice: Treat large backfills as a separate engineering exercise. Evaluate the historical scope, expected aggregation volume, and available resources before initiating the operation.
- Be Careful with High-Cardinality Grouping Keys
Another important factor is the cardinality of the grouping columns.
A materialized view that groups data into a relatively small number of combinations is generally easier to maintain than one producing millions or billions of distinct combinations.
High cardinality affects materialization in several ways:
- More aggregated rows must be maintained.
- More existing data may need to be examined during matching.
- The number of row replacements can increase.
- The materialized dataset can become significantly larger.
For example, grouping by a small number of categories may produce a compact MV.
Adding highly granular identifiers to the grouping keys can dramatically increase the number of combinations.
Before creating an MV, consider whether every grouping column is truly necessary.
Best practice: Avoid grouping configurations that produce many millions of distinct combinations unless the use case genuinely requires that level of granularity.
When high cardinality is unavoidable, pay particular attention to lookback configuration, partitioning, and materialization performance.
- Consider Partitioning the Base Table, the MV, or Both
Partitioning can help optimize materialized view workloads, particularly when working with large datasets.
An important point is that partitioning decisions for the source table and the materialized view should be evaluated independently.
You can partition:
- The source table.
- The materialized view.
- Both the source table and the materialized view.
When Should You Partition the Source Table?
Partitioning the source table may be beneficial when a meaningful portion of the workload queries the source table directly rather than relying exclusively on the MV.
As a practical guideline, consider source-table partitioning when more than approximately 10% of queries access the source table directly.
The benefit depends on the actual query patterns, filtering characteristics, and data distribution.
When Should You Partition the MV?
Partitioning the MV itself becomes more relevant as the volume of materialized data grows.
A useful guideline is to consider MV partitioning when the view adds at least 64 GB of materialized data per day.
At this scale, an appropriate partitioning strategy may improve data organization and reduce the overhead associated with maintaining large volumes of materialized data.
These thresholds should be treated as starting points for evaluation rather than universal rules.
Best practice: Make partitioning decisions based on the actual workload, data volume, and access patterns. Partitioning adds complexity and should be introduced when there is a clear expected benefit.
- How Should You Query a Materialized View?
Creating and maintaining an efficient MV is only part of the story.
The way applications query the MV can have a significant impact on both performance and data freshness.
There are three common approaches, each offering a different balance between freshness and query cost.
Option 1: Query the MV Directly
KQL
MyMaterializedView
| where Timestamp > ago(1h)
| summarize Total = sum(EventCount) by Category
When you query the MV by its name, the query engine provides a view of the data that includes both:
- Data already processed by materialization.
- Data that has arrived in the source table but has not yet been materialized.
Depending on the ingestion path, the query may also need to process recent data still residing in the row store that has not yet been converted into columnar extents.
This approach provides the freshest available results.
However, combining materialized and non-materialized data can introduce additional processing overhead.
If materialization is significantly behind ingestion, the amount of unmaterialized data can become substantial, making these queries expensive.
When to use it: When applications require the freshest available results and can tolerate the additional query cost.
Option 2: Query Only the Materialized Portion
KQL
materialized_view("MyMaterializedView")
| where Timestamp > ago(1h)
| summarize Total = sum(EventCount) by Category
The materialized_view() function allows you to query only the data that has already been materialized.
Unlike querying the MV directly, this approach does not combine the materialized data with the unmaterialized delta.
As a result, queries can be significantly faster, particularly when the unmaterialized portion is large.
The tradeoff is freshness.
The results reflect the latest completed materialization rather than all data currently available in the source table.
If the MV has a materialization lag of several minutes, the query results may be missing data ingested during that period.
When to use it: For analytical workloads where query performance is more important than immediate data freshness.
Option 3: Query with a Maximum Acceptable Lag
KQL
materialized_view("MyMaterializedView", 2m)
| where Timestamp > ago(1h)
| summarize Total = sum(EventCount) by Category
This option combines the benefits of the previous two approaches.
The second parameter specifies the maximum acceptable materialization lag.
In this example, the threshold is two minutes.
The behavior is:
- Materialization lag is two minutes or less: The query uses only the materialized portion of the MV, providing faster execution.
- Materialization lag exceeds two minutes: The query behaves like a direct query against the MV, including the unmaterialized data to provide fresher results.
This approach allows applications to benefit from efficient materialized-only queries during normal operation while automatically prioritizing freshness when materialization falls behind.
The threshold does not control how frequently materialization occurs. It controls which query execution approach is used based on the current materialization lag.
When to use it: When applications have a defined freshness requirement but should avoid the cost of processing unmaterialized data whenever possible.
Comparing the Three Approaches
|
Query method |
Data freshness |
Query performance |
Recommended scenario |
|
MyMaterializedView |
Freshest available data |
Potentially expensive |
Applications requiring immediate freshness |
|
materialized_view("MyMaterializedView") |
Depends on materialization lag |
Typically fastest |
Analytics where some lag is acceptable |
|
materialized_view("MyMaterializedView", 2m) |
Freshness-aware |
Adaptive |
Applications balancing freshness and performance |
For many applications, the third option provides an attractive balance between performance and freshness.
- Final Recommendations
Based on my experience working with customers, successful materialized views are usually the result of a few deliberate architectural choices.
Here are the recommendations I consider most important:
- Understand the materialization process. Remember that each cycle may need to match new aggregations against existing materialized data.
- Keep MV definitions simple. Move expensive transformations and suitable joins into update policies where practical.
- Configure lookback carefully. Use the shortest lookback period that safely covers the expected arrival patterns of related records.
- Plan historical backfills separately. Avoid processing years of historical data unless the use case requires it. Consider backfill by moving extents for very large datasets.
- Control grouping cardinality. Be aware of the operational cost of maintaining millions of distinct grouping combinations.
- Evaluate partitioning strategically. Consider the size and access patterns of both the source table and the MV.
- Choose the right query method. Don't automatically query the MV by name if the application can tolerate some materialization lag. Use materialized_view() and its maximum-lag parameter to optimize the balance between freshness and performance.
Conclusion
Materialized views can dramatically improve query performance, but their success depends on more than the aggregation query itself.
The most important consideration is whether the materialization process can consistently keep up with the incoming data.
That depends on the complexity of the aggregation, the number of grouping combinations, the lookback period, the amount of existing data that must be updated, and the overall ingestion workload.
Equally important is choosing the right way to query the MV. Applications that do not require immediate freshness can often achieve significantly better performance by querying only the materialized portion.
The goal is not simply to create a materialized view that works. It's to design one that remains efficient, predictable, and sustainable as the workload grows.
Published Dec 01, 2026
Version 1.0DanyHoter
Microsoft
Joined October 06, 2021
Azure Data Explorer Blog
Follow this blog board to get notified when there's new activity