Get startedGet started for free

Real-time processing with Change Feed

1. Real-time processing with Change Feed

Welcome back! In this video, we’ll explore Azure Cosmos DB Change Feed, a feature that enables real-time, event-driven processing of data changes.

2. Cosmos DB change feed

Change Feed allows developers to react instantly whenever data in a Cosmos DB container is created or updated, without writing complex polling logic. It’s how modern, responsive systems stay in sync across services.

3. What is the Change Feed?

The Change Feed is a continuous stream of changes, or "events", in your Cosmos DB container. It tracks inserts and updates in order of occurrence and makes them available for processing in real time. Think of it as a live activity log that lists everything new happening in your database.

4. Unread mail

Each change appears once and stays available until you process it, like reading unread emails in your inbox, the number stays there until you've checked it.

5. How developers use Change Feed

Developers can consume the Change Feed in several ways: Pull Model: In this method, the application pulls data from the Change Feed when it needs to. Developers write code that periodically checks for new changes using the SDK or the ChangeFeedProcessor class. Think of it as asking, “Hey, has anything new happened?” at regular intervals. This gives developers more control, for example, they can decide when and how often to process new changes. Push Model: Here, the system pushes changes automatically to another component when they occur. With Azure Functions, you can use a Cosmos DB Trigger that runs automatically whenever a new change appears. Think of it like instantly hearing a ping when you receive a new message instead of manually checking every 5 minutes. This makes the process event-driven, meaning the function reacts in real time, without needing to check for updates.

6. Example: Azure Function trigger

Example: When a new order document is added to the Cosmos DB, an Azure Function triggers instantly to process the order, send a confirmation email, or update a dashboard.

7. Change Feed architecture

When you read data from the Change Feed in Azure Cosmos DB, the system needs a way to remember where you left off: that's where leases come in. A lease is like a record of progress. It keeps track of which changes your application has already processed, so it knows exactly where to resume next time. Think of leases as bookmarks that remember the last change you read instead of randomly opening a book again to find where you left off. This ensures your consumers never miss or reprocess events, even if they restart.

8. Why use Change Feed?

The Change Feed in Azure Cosmos DB is perfect for scenarios where your system needs to react to data changes, instead of waiting for someone to query or refresh it. It continuously streams new or updated items, allowing your applications to act right away.

9. Use cases

So, what are the use cases? Event-driven pipelines, these are automated workflows that start when a specific event occurs. Real-time analytics, you can use Change Feed to feed live updates into dashboards or reports. Data synchronization, in large systems, different applications or microservices often store and use data independently. Change Feed helps keep all of them synchronized. Downstream integrations, sometimes, you need to send your data elsewhere - for example, to Azure Event Hubs or Azure Service Bus.

10. Real-time event source

The Change Feed transforms Cosmos DB from a passive data store into a real-time event source. When combined with Azure Functions, you can build applications that respond instantly to data events, all without managing infrastructure.

11. Let's practice!

Let's put this into practice in the next exercises!

Create Your Free Account

or

By continuing, you accept our Terms of Use, our Privacy Policy and that your data is stored in the USA.