- In the push model, changes are immediately sent to consumers as soon as they occur. This approach is ideal for event-driven architectures where continuous polling is not desirable.
- In the pull model, the application periodically polls the change feed to retrieve changes. This method offers greater control over when and how frequently changes are processed, making it suitable for scenarios where immediate reaction is not required. However, it does demand additional management of the polling infrastructure to maintain consistency.

-
Azure Functions with Cosmos DB triggers
Automatically trigger functions when changes occur. This option removes the need for continuous polling and simplifies scaling within event-driven architectures. -
Change Feed Processor Library
Available as part of the Cosmos DB SDK for .NET and Java, this library facilitates reading the change feed and distributing events across multiple consumers, ensuring horizontally scalable processing.

Key Components of the Change Feed Processor Architecture
The change feed processor architecture comprises four main components:- Monitored Container: The source container where changes occur.
- Lease Container: Manages distributed processing by coordinating leases.
- Compute Instance: Processes the changes.
- Delegate: Contains custom logic to handle each change.
For optimized processing and scalability, ensure that your lease container is appropriately provisioned to handle the expected throughput.
Sample Code: Setting Up the Change Feed Processor
The following C# code snippet demonstrates how to set up the change feed processor using the Cosmos DB SDK. In this example, the processor is initialized with the source container, lease container, and a delegate function that processes the changes.- Configuration values define the database, source container, and lease container names.
- The change feed processor is constructed using the
GetChangeFeedProcessorBuildermethod. The delegateHandleChangesAsyncis provided to process the incoming changes. - The processor starts asynchronously, continuously monitoring and handling changes without requiring manual polling.
This sample demonstrates how to leverage Azure Cosmos DB’s change feed functionality to create efficient, real-time data processing systems. The underlying infrastructure manages scaling and consistency, allowing you to focus on processing the data.