πŸ”’ Guided

Pre-launch preview. Authorised access only.

Incorrect code

Guided by A Guide to Cloud
Explore AB-900 AI-901
Guided DP-420 Domain 3
Domain 3 β€” Module 1 of 3 33%
15 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 3: Integrate and Move Data Premium ⏱ ~16 min read

Change Feed with Azure Functions and Processors

Implement real-time data processing with the Cosmos DB change feed using Azure Functions triggers and the Change Feed Processor library β€” including lease containers, parallel processing, and feed modes.

What is the change feed?

β˜• Simple explanation

Think of a security camera recording every change in a store. The change feed is Cosmos DB’s built-in recording of every insert and update. Your application can β€œwatch the tape” in real time and react β€” send a notification, update a search index, trigger a calculation.

Deletes aren’t recorded in the default mode (you’d use soft-deletes with a TTL). The newer β€œall versions and deletes” mode captures everything.

The change feed is a persistent, ordered log of changes (inserts and updates) to items in a Cosmos DB container. Key properties:

  • Ordered: Changes arrive in modification order within each logical partition.
  • Persistent: The feed is durable β€” you can read from any point in time.
  • Push model: Azure Functions and the Change Feed Processor push changes to your code.
  • Pull model: You can also pull changes manually using the SDK.
  • No extra cost: Reading the change feed consumes RU/s but there’s no separate charge for the feature.

Amara’s scenario: real-time sensor processing

πŸ“‘ Amara at SensorFlow ingests 500M IoT events per day into a Cosmos DB container partitioned by /deviceId. She needs to:

  • Trigger alerts when a sensor reading exceeds a threshold
  • Update a dashboard materialized view in near-real-time
  • Feed analytics by streaming changes to a data warehouse

The change feed is the backbone of all three.

Azure Functions Cosmos DB trigger

The simplest way to consume the change feed β€” Azure Functions handles the infrastructure:

[FunctionName("SensorAlerts")]
public static void Run(
    [CosmosDBTrigger(
        databaseName: "sensorflow",
        containerName: "readings",
        Connection = "CosmosDBConnection",
        LeaseContainerName = "leases",
        CreateLeaseContainerIfNotExists = true
    )] IReadOnlyList<SensorReading> changes,
    ILogger log)
{
    foreach (SensorReading reading in changes)
    {
        if (reading.Temperature > 85.0)
        {
            log.LogWarning($"ALERT: Device {reading.DeviceId} at {reading.Temperature}Β°C");
            // Send notification, write to alert container, etc.
        }
    }
}

Key points:

  • The trigger creates and manages the lease container automatically
  • Changes arrive as a batch β€” process the entire batch, not item by item
  • If the function fails, the batch is retried from the last checkpoint
  • The function scales automatically based on the number of physical partitions
πŸ’‘ Exam tip: lease container purpose

The lease container tracks which changes have been processed and by which consumer. It stores one lease document per physical partition of the monitored container. This enables:

  • Checkpointing: If your processor crashes, it resumes from the last checkpoint, not from the beginning.
  • Parallel processing: Multiple instances claim different leases, distributing work.
  • Load balancing: If an instance dies, its leases are redistributed to surviving instances.

The lease container must be in the same Cosmos DB account as the monitored container.

Change Feed Processor library

For more control than Azure Functions, use the Change Feed Processor directly:

Container leaseContainer = cosmosClient
    .GetDatabase("sensorflow")
    .GetContainer("leases");

Container monitoredContainer = cosmosClient
    .GetDatabase("sensorflow")
    .GetContainer("readings");

ChangeFeedProcessor processor = monitoredContainer
    .GetChangeFeedProcessorBuilder<SensorReading>(
        processorName: "dashboardUpdater",
        onChangesDelegate: HandleChangesAsync)
    .WithInstanceName("instance-1")
    .WithLeaseContainer(leaseContainer)
    .WithStartTime(DateTime.MinValue.ToUniversalTime()) // from beginning
    .Build();

await processor.StartAsync();

static async Task HandleChangesAsync(
    ChangeFeedProcessorContext context,
    IReadOnlyCollection<SensorReading> changes,
    CancellationToken cancellationToken)
{
    foreach (SensorReading reading in changes)
    {
        Console.WriteLine($"Partition {context.LeaseToken}: {reading.DeviceId}");
    }
}

Change feed modes

FeatureLatest Version (default)All Versions and Deletes (preview)
What's capturedMost recent version of inserts/updatesEvery version of every change + deletes
Deletes❌ Not captured (use soft-delete + TTL)βœ… Captured with metadata
Intermediate versions❌ Only latest if multiple changes before readβœ… Every intermediate version
RetentionUnlimitedConfigured by continuous backup retention window
Use caseEvent reactions, materialized viewsAudit trails, full change history, CDC
PrerequisitesNoneContinuous backup enabled, NoSQL API only
πŸ’‘ Exam tip: soft-delete pattern

In Latest Version mode (default), deletes are NOT in the change feed. The standard workaround is the soft-delete pattern:

  1. Instead of deleting, set a deleted: true flag and a TTL value
  2. The change feed captures this as an update (the flag change)
  3. Your processor sees the deleted: true flag and reacts accordingly
  4. The TTL auto-removes the document after the specified period

This is a very common exam question β€” know the soft-delete workaround.

Starting position

OptionDescription
From beginningProcess all historical changes β€” useful for rebuilding a materialized view
From nowOnly process new changes β€” default for Azure Functions
From specific timeResume from a point-in-time β€” disaster recovery scenarios
From continuation tokenResume from exact position β€” programmatic checkpointing

Parallel processing and scaling

The change feed is partitioned by physical partition. Each physical partition can be processed by exactly one consumer instance at a time.

Container with 6 physical partitions:
  Instance A: processes partitions 1, 2
  Instance B: processes partitions 3, 4
  Instance C: processes partitions 5, 6

If Instance B crashes:
  Instance A: processes partitions 1, 2, 3  ← acquires B's lease
  Instance C: processes partitions 4, 5, 6  ← acquires B's lease

Scaling rule: You can have at most as many consumer instances as physical partitions. More instances than partitions means some sit idle.

🎬 Video walkthrough

🎬 Video coming soon

Change Feed Processing β€” DP-420 Module 15

Change Feed Processing β€” DP-420 Module 15

~16 min

Flashcards

Question

What does the lease container do in change feed processing?

Click or press Enter to reveal answer

Answer

It tracks processing state β€” one lease per physical partition. It enables checkpointing (resume after crash), parallel processing (distribute partitions across instances), and load balancing (redistribute leases if an instance fails). Must be in the same Cosmos DB account.

Click to flip back

Question

Does the default change feed mode capture deletes?

Click or press Enter to reveal answer

Answer

No β€” Latest Version mode only captures inserts and updates. For deletes, use either: (1) the soft-delete pattern (set a deleted flag + TTL), or (2) All Versions and Deletes mode (requires continuous backup and new containers).

Click to flip back

Question

What is the maximum number of change feed consumer instances for a container?

Click or press Enter to reveal answer

Answer

Equal to the number of physical partitions. Each physical partition's changes are processed by exactly one instance at a time. Extra instances beyond the partition count sit idle, waiting to acquire a lease.

Click to flip back

Question

What happens if a change feed processor instance crashes mid-batch?

Click or press Enter to reveal answer

Answer

The batch is retried from the last checkpoint. The lease is released and acquired by another instance (or the restarted instance). No changes are lost because the change feed is persistent and the lease tracks the last successful position.

Click to flip back

Knowledge Check

Knowledge Check

Amara's SensorFlow container has 8 physical partitions. She deploys 12 Azure Functions instances to process the change feed. How many instances will actively process changes?

Knowledge Check

Amara needs to detect when sensors are physically removed (deleted from the database). She's using the default change feed mode. What's the best approach?

Knowledge Check

Amara wants to rebuild a materialized view from scratch by reprocessing all historical changes. How should she configure the change feed processor?


Next up: Analytical Workloads β€” how Synapse Link and Fabric Mirroring bring analytics to your Cosmos DB data without impacting transactional performance.

← Previous

Multi-Region Writes and Conflict Resolution

Next β†’

Analytical Workloads: Synapse Link and Fabric Mirroring

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.