πŸ”’ Guided

Pre-launch preview. Authorised access only.

Incorrect code

Guided by A Guide to Cloud
Explore AB-900 AI-901 aws-aif-c01
Guided DP-420 Domain 4
Domain 4 β€” Module 4 of 4 100%
21 of 28 overall

DP-420 Study Guide

Domain 1: Design and Implement Data Models

  • Cosmos DB β€” The Big Picture Free
  • Designing Your Data Model Free
  • Partition Key Strategy Free
  • Synthetic and Hierarchical Partition Keys Free
  • Relationships β€” Embedding vs Referencing Free
  • SDK Connectivity and Client Configuration Free
  • SDK CRUD Operations and Transactions Free
  • SQL Queries in Cosmos DB Free
  • SDK Query Pagination and LINQ Free
  • Server-Side Programming Free
  • Transactions in Practice Free

Domain 2: Design and Implement Data Distribution

  • Global Replication and Failover
  • Consistency Levels: Five Choices, Real Trade-Offs
  • Multi-Region Writes and Conflict Resolution

Domain 3: Integrate and Move Data

  • Change Feed with Azure Functions and Processors
  • Analytical Workloads: Synapse Link and Fabric Mirroring
  • Data Movement: ADF, Kafka, and Spark Connectors

Domain 4: Optimize Query and Operation Performance

  • Indexing Policies: Range, Spatial, and Composite
  • Request Units and Query Cost Optimization
  • Integrated Cache and Dedicated Gateway
  • Change Feed Patterns: Materialized Views and Estimator

Domain 5: Maintain an Azure Cosmos DB Solution

  • Monitoring: Metrics, Logs, and Alerts
  • Backup and Restore: Periodic vs Continuous
  • Network Security: Firewalls, VNets, and Private Endpoints
  • Data Security: Encryption, Keys, and RBAC
  • Cost Optimization: Throughput Modes and RU Strategy
  • DevOps: Infrastructure as Code and Deployments
  • Exam Strategy and Cross-Domain Review

DP-420 Study Guide

Domain 1: Design and Implement Data Models

  • Cosmos DB β€” The Big Picture Free
  • Designing Your Data Model Free
  • Partition Key Strategy Free
  • Synthetic and Hierarchical Partition Keys Free
  • Relationships β€” Embedding vs Referencing Free
  • SDK Connectivity and Client Configuration Free
  • SDK CRUD Operations and Transactions Free
  • SQL Queries in Cosmos DB Free
  • SDK Query Pagination and LINQ Free
  • Server-Side Programming Free
  • Transactions in Practice Free

Domain 2: Design and Implement Data Distribution

  • Global Replication and Failover
  • Consistency Levels: Five Choices, Real Trade-Offs
  • Multi-Region Writes and Conflict Resolution

Domain 3: Integrate and Move Data

  • Change Feed with Azure Functions and Processors
  • Analytical Workloads: Synapse Link and Fabric Mirroring
  • Data Movement: ADF, Kafka, and Spark Connectors

Domain 4: Optimize Query and Operation Performance

  • Indexing Policies: Range, Spatial, and Composite
  • Request Units and Query Cost Optimization
  • Integrated Cache and Dedicated Gateway
  • Change Feed Patterns: Materialized Views and Estimator

Domain 5: Maintain an Azure Cosmos DB Solution

  • Monitoring: Metrics, Logs, and Alerts
  • Backup and Restore: Periodic vs Continuous
  • Network Security: Firewalls, VNets, and Private Endpoints
  • Data Security: Encryption, Keys, and RBAC
  • Cost Optimization: Throughput Modes and RU Strategy
  • DevOps: Infrastructure as Code and Deployments
  • Exam Strategy and Cross-Domain Review
Domain 4: Optimize Query and Operation Performance Premium ⏱ ~16 min read

Change Feed Patterns: Materialized Views and Estimator

Implement advanced change feed patterns β€” materialized views, denormalization propagation, event-driven aggregation, the change feed estimator for lag monitoring, and triggering downstream actions.

Change feed as an event backbone

β˜• Simple explanation

The change feed is like a conveyor belt in a factory. Module 15 taught you how to set up the belt (Azure Functions, processors). Now we’re building the machines at the end of the belt β€” machines that create summary reports, update other databases, send alerts, and keep everything in sync.

The change feed isn’t just for reacting to individual changes. It enables powerful architectural patterns:

  • Materialized views: Pre-compute query results into dedicated containers.
  • Denormalization propagation: Keep copied data in sync across containers.
  • Event-driven aggregation: Maintain running totals, averages, and counts.
  • Downstream triggers: Push notifications, update search indexes, feed analytics.

Amara’s patterns at SensorFlow

πŸ“‘ Amara at SensorFlow uses the change feed to power three critical patterns:

  1. Dashboard materialized view β€” pre-computed β€œlatest reading per device” for fast dashboard loads
  2. Alert propagation β€” when a reading exceeds threshold, write to an alerts container
  3. Lag monitoring β€” ensure processing stays within 30 seconds of real-time

Pattern 1: Materialized views

A materialized view is a pre-computed, query-optimised container that’s kept in sync via the change feed.

Source container: "readings"              Target container: "device-latest"
  partitioned by /deviceId                  partitioned by /region
  500M events/day                           10,000 documents (one per device)

Change feed processor: on each new reading,
  upsert into device-latest with the latest values
static async Task HandleChangesAsync(
    ChangeFeedProcessorContext context,
    IReadOnlyCollection<SensorReading> changes,
    CancellationToken ct)
{
    foreach (SensorReading reading in changes)
    {
        // Upsert into the materialized view container
        var latest = new DeviceLatest
        {
            id = reading.DeviceId,           // one doc per device
            Region = reading.Region,          // partition key for view
            DeviceId = reading.DeviceId,
            Temperature = reading.Temperature,
            LastUpdated = reading.Timestamp
        };

        await latestContainer.UpsertItemAsync(latest,
            new PartitionKey(latest.Region));
    }
}

Why this is powerful:

  • The dashboard reads 10,000 docs from device-latest (cheap, single-partition queries by region) instead of scanning 500M docs in readings
  • Different partition key on the view container enables query patterns not possible on the source
πŸ’‘ Exam tip: materialized views reduce query cost

Materialized views trade write cost (change feed processing + upserts) for read cost savings (cheap reads from the pre-computed view). This is ideal when data is written once but read many times (high read-to-write ratio).

The exam may present a scenario where a complex, expensive query runs frequently. The answer is often: β€œUse the change feed to maintain a materialized view.”

Pattern 2: Denormalization propagation

When you embed (denormalize) data across containers, the change feed keeps copies in sync:

"products" container (source of truth)
  { id: "P1", name: "Sensor-X", price: 29.99 }

"orders" container (denormalized copy)
  { id: "O1", productName: "Sensor-X", productPrice: 29.99, ... }

When product P1's price changes:
  Change feed processor updates ALL orders referencing P1
static async Task PropagateProductChanges(
    ChangeFeedProcessorContext context,
    IReadOnlyCollection<Product> changes,
    CancellationToken ct)
{
    foreach (Product product in changes)
    {
        // Find all orders with this product and update denormalized fields
        var query = new QueryDefinition(
            "SELECT * FROM c WHERE c.productId = @pid")
            .WithParameter("@pid", product.Id);

        using FeedIterator<Order> iterator =
            ordersContainer.GetItemQueryIterator<Order>(query);

        while (iterator.HasMoreResults)
        {
            FeedResponse<Order> orders = await iterator.ReadNextAsync();
            foreach (Order order in orders)
            {
                order.ProductName = product.Name;
                order.ProductPrice = product.Price;
                await ordersContainer.UpsertItemAsync(order,
                    new PartitionKey(order.CustomerId));
            }
        }
    }
}

Pattern 3: Event-driven aggregation

Maintain running aggregates without expensive queries:

// Maintain a running average temperature per device
static async Task UpdateAggregates(
    ChangeFeedProcessorContext context,
    IReadOnlyCollection<SensorReading> changes,
    CancellationToken ct)
{
    foreach (SensorReading reading in changes)
    {
        // Read current aggregate
        var response = await aggregatesContainer.ReadItemAsync<DeviceAggregate>(
            reading.DeviceId, new PartitionKey(reading.DeviceId));

        var agg = response.Resource;
        agg.ReadingCount++;
        agg.TotalTemperature += reading.Temperature;
        agg.AverageTemperature = agg.TotalTemperature / agg.ReadingCount;
        agg.MaxTemperature = Math.Max(agg.MaxTemperature, reading.Temperature);

        await aggregatesContainer.UpsertItemAsync(agg,
            new PartitionKey(agg.DeviceId));
    }
}

The change feed estimator

The estimator monitors processing lag β€” how far behind your processor is from the latest changes:

ChangeFeedProcessor estimator = monitoredContainer
    .GetChangeFeedEstimatorBuilder(
        processorName: "dashboardUpdater",
        estimationDelegate: HandleEstimation)
    .WithLeaseContainer(leaseContainer)
    .Build();

await estimator.StartAsync();

static async Task HandleEstimation(
    long remainingWork,
    CancellationToken ct)
{
    Console.WriteLine($"Estimated lag: {remainingWork} changes behind");

    if (remainingWork > 10000)
    {
        // Alert: processor is falling behind!
        // Consider scaling up instances or investigating bottlenecks
    }
}

Key details:

  • remainingWork is the estimated number of unprocessed changes across all partitions
  • The estimator reads from the same lease container as the processor
  • It does NOT process changes β€” it only monitors
  • Use it to trigger scaling decisions or alerting
πŸ’‘ Exam tip: estimator vs processor

The change feed estimator and processor are separate components:

  • The processor reads and processes changes
  • The estimator monitors how far behind the processor is

They share the same lease container β€” the estimator reads lease checkpoints to calculate lag. You can run the estimator in a separate process (e.g., a monitoring Azure Function).

Pattern 4: Triggering downstream actions

The change feed can trigger actions in external systems:

Downstream ActionExample
Push notificationsAlert mobile app when sensor threshold exceeded
Search index updateSync changes to Azure Cognitive Search
Analytics pipelineStream changes to Event Hubs or Kafka
Cache invalidationClear Redis or CDN cache when data changes
Audit logWrite change history to a separate container

🎬 Video walkthrough

🎬 Video coming soon

Change Feed Patterns β€” DP-420 Module 21

Change Feed Patterns β€” DP-420 Module 21

~16 min

Flashcards

Question

What is a materialized view in Cosmos DB?

Click or press Enter to reveal answer

Answer

A pre-computed, query-optimised container that's kept in sync with the source container via the change feed. It trades write cost (change feed processing + upserts) for read cost savings (cheap reads from the view).

Click to flip back

Question

What does the change feed estimator measure?

Click or press Enter to reveal answer

Answer

The estimated number of unprocessed changes (lag) across all partitions. It reads from the same lease container as the processor to calculate how far behind processing is. Use it for monitoring and scaling decisions.

Click to flip back

Question

How does denormalization propagation work with the change feed?

Click or press Enter to reveal answer

Answer

When the source of truth changes, the change feed processor finds all denormalized copies in other containers and updates them. This keeps embedded/copied data in sync across containers without manual coordination.

Click to flip back

Question

What resource does the change feed estimator share with the processor?

Click or press Enter to reveal answer

Answer

The lease container. The estimator reads lease checkpoint positions to calculate how many changes the processor hasn't yet processed. They use the same lease container but serve different purposes (processing vs monitoring).

Click to flip back

Knowledge Check

Knowledge Check

Amara's dashboard query scans 500M readings to find the latest value per device, costing 50,000 RU per execution. The dashboard refreshes every 30 seconds. What's the best optimisation?

Knowledge Check

The change feed estimator reports remainingWork of 50,000 changes. What does this mean?

Knowledge Check

GlobeCart embeds product names in order documents. When a product is renamed, which pattern keeps order documents in sync?


Next up: Monitoring β€” metrics, logs, alerts, and Azure Monitor insights for keeping your Cosmos DB solution healthy.

← Previous

Integrated Cache and Dedicated Gateway

Next β†’

Monitoring: Metrics, Logs, and Alerts

Guided

I learn, I simplify, I share.

A Guide to Cloud YouTube Feedback

© 2026 Sutheesh. All rights reserved.

Guided is an independent study resource and is not affiliated with, endorsed by, or officially connected to Microsoft. Microsoft, Azure, and related trademarks are property of Microsoft Corporation. Always verify information against Microsoft Learn.