Introduction to the Change Feed
Learn how to use the change feed feature of Cosmos DB and implement reactive cloud applications.
We'll cover the following...
Introduction
The change feed feature in Cosmos DB lets us know when documents change in a specific container. Developers often overlook it since this feature is not present in most traditional databases. The change feed makes Cosmos DB an excellent choice for event-driven architectures. Applications can react automatically and asynchronously to data changes.
Here are some examples of what we can do:
Send notifications to users
Call other APIs
Stream logs or analytics
Materialize views
Invalidate caches
Event sourcing
Biggest limitations
The change feed has some limitations that we should keep in mind before making any decisions:
By default, it doesn’t process deleted documents. To do so, we need to add a property, for example,
isDeleted
, and set it totrue
. Once processed by the change feed, we can delete the document.By default, only the latest version of a document appears in the feed.
The changes are guaranteed to be sorted only within the same logical partition.
We can ensure that each change is processed at least once; if we use eventual consistency, we might receive the same event multiple times and need to handle it.
It cannot replace products like Apache Kafka because of its limitations. However, there are connectors to feed Apache Kafka or Apache Spark ...