Understanding the Change Feed and Its Processor
This lesson explains what the change feed contains, its two modes, and how the change feed processor distributes and checkpoints work with leases.
Learning outcomes
After completing this lesson, you will be able to:
- Describe the ordering and cost of the change feed.
- Compare latest version and all versions and deletes modes.
- Explain leases, checkpoints and at-least-once delivery.
- Distinguish deployment units by processor name.
What the change feed is
Every Cosmos DB container has a change feed: a persistent record of item changes in the order in which they occurred. Applications read it to react to new and updated data without polling the container with queries. Typical uses in AI back ends include generating or refreshing embeddings when a document changes, invalidating cached answers, copying data into a search index or analytical store, and starting workflows when an order is created.
Order is guaranteed within each partition key value, not across the whole container, because partitions are processed in parallel. Reading the change feed consumes RUs from the monitored container's throughput, so a busy reader needs headroom in the container's provisioned or autoscale throughput.
The change feed
Change feed modes
The change feed can be read in two modes, which differ in what they record.
Because latest version mode does not record deletes, a common pattern is the soft delete: the application sets a property such as "deleted": true and a time to live (TTL) on the item. The update appears in the change feed, so consumers remove the item from their own stores, and the TTL removes the item from the container afterwards. All versions and deletes mode requires continuous backup on the account.
Which change feed mode?
How the change feed processor works
Reading the change feed reliably at scale is harder than it looks: work must be split across instances, progress must be saved so that a restart does not reprocess everything, and failures must not lose changes. The change feed processor library does this. It has four components.
- The monitored container, whose changes are read.
- The lease container, which stores one lease document per partition range. A lease records which instance owns the range and a checkpoint of how far it has been processed.
- One or more compute instances, each with a unique instance name, which run the processor.
- The delegate, the application code that receives each batch of changes.
Each instance reads the changes for the leases it owns, calls the delegate, and only after the delegate returns successfully advances the lease's checkpoint. If the delegate throws an exception, the batch is delivered again, which gives at-least-once delivery; handlers must therefore be idempotent. Instances that share a processor name and lease container form a deployment unit and divide the leases evenly between them; a different processor name creates an independent consumer that receives every change too.
-
Read
Each instance reads the change feed for the partition ranges whose leases it owns.
-
Wait
If there are no changes, it sleeps for the poll interval and reads again.
-
Deliver
If there are changes, it passes the batch to the delegate.
-
Checkpoint
When the delegate succeeds, it saves the new position in the lease, then reads again.
The following diagram shows the two deployment units and the shared lease container.

Processor components
Scaling, starting points and failures
Because work is divided by lease, adding instances spreads leases across more machines, up to one instance per lease; extra instances sit idle. Leases are rebalanced automatically when instances join or leave and when the monitored container splits partitions. Default lease timings are a lease acquire check every 17 seconds, renewal every 13 seconds and expiry after 60 seconds, so a crashed instance's leases move to another instance after about a minute.
By default, a processor that starts for the first time reads changes from now; earlier changes are not delivered. A start time, or reading from the beginning of the container's life, can be configured only before the lease container is first initialized. A delegate that fails repeatedly on one bad item would block its partition range forever, so the recommended pattern is to catch the error, write the failed item to an error store such as another container or a queue, and let the batch complete. The change feed estimator reports how far behind each lease is, which is the processor's lag metric.
The processor library itself is part of the .NET and Java SDKs. Applications in other languages, including Python, use either the Azure Functions Cosmos DB trigger, which runs the change feed processor for them, or the pull model, both described in the next topic. The concepts of leases, checkpoints, at-least-once delivery and the start position apply to all of them.
Permissions
With Microsoft Entra authentication, the reader needs permission to read the change feed on the monitored container (the readChangeFeed data action) and to read, create, replace, delete and query items in the lease container. Cosmos DB Built-in Data Contributor on both covers this.
Running the processor
Two consumers of one change feed
An orders container must feed two independent processes: one generates embeddings for new orders' notes, and one invalidates a Redis cache. Each process runs on three instances for throughput. The team wants both processes to receive every change and to share one lease container.
Each process is a separate deployment unit, so each must use a different processor name (or, in Azure Functions, a different lease prefix) while pointing at the same lease container. Within each unit, the three instances use different instance names and share the leases, so each change is processed once per unit. Both units receive every change.
Using the same processor name for both processes would merge them into one deployment unit, and each change would reach only one of the two processes. Using one instance name on all three instances would prevent the processor from distributing leases.
Two processes must each receive every change from one container. How must their change feed processors be configured?
Show answer
With different processor names (or lease prefixes), so they form separate deployment units. The same name would split the changes between them.
Exam Tips
Remember for the exam
- Order is guaranteed per partition key value; reading the feed consumes RUs.
- Latest version mode has no deletes; use soft delete with TTL, or all versions and deletes mode.
- Leases in a lease container record ownership and checkpoints; delivery is at least once.
- Same processor name and lease container = one deployment unit; a different name = an independent consumer.